Author | Message | Time |
---|---|---|
MoNksBaNe_Agahnim | I've been reading a lot recently and I keep coming across %<letter> commands.... example.... [code] [Pulled from 6.0 version of Greet Bot] Send("%c%c%s\r\n%s\r\n", 0x03, 0x04, szLoginName, szPassword); [/code] What exactly are these types of command, %c %s %d (may be others not sure) Thanks for any and all help - MBane_Agahnim | March 16, 2004, 3:59 PM |
Dante | I don't know what %c and %s do, but I know what %d does. heres some examples of shit: scanf("%d", &bob); in this case, when the user types in a decimal number, it will assign that number to the variable bob. So now that we got that out of the way, that Send stuff sends the data. Send("%d", bob); That will send whatever you typed in at scanf. Thats the only way I could explain it, maybe someone else can help you better. | March 16, 2004, 4:03 PM |
AC_Drkan | Ok, %c is individual characters like a, b, c, d %s is a string of data like "i am cool" Dan | March 16, 2004, 4:17 PM |
iago | Look up printf(), scanf() style formatting. | March 16, 2004, 4:18 PM |
Eli_1 | %c Character 'a' %d or %i -- Signed decimal integer 392 %e Scientific notation (mantise/exponent) using e character 3.9265e2 %f Decimal floating point 392.65 %g Use shorter %e or %f 392.65 %o Signed octal 610 %s String of characters sample %u Unsigned decimal integer 7235 %x Unsigned hexadecimal integer 7fa %p Address pointed by the argument B800:0000 | March 16, 2004, 7:32 PM |
Mephisto | I don't know what you mean by commands, but I think you're getting at operators. But nontheless, they're neither. They're format identifiers C uses to generally determine what type of variable it is going to be dealing with. For instance, if you use %s, the function you're using with it that uses these format identifiers (printf, scanf, etc.) will expect a string. Generally, the format identifiers go in quotes (e.g. printf("%d") or scanf("%d")) and the variable which you're going to be using that corresponds to that format identifier is not in quotes (e.g. printf("%d", theintgervar) or scanf("%d", &theintegervar)). You should learn about what functions actually use these. Generally, the concept/syntax is the same for any use of them, though. | March 16, 2004, 8:02 PM |
Skywing | You can also specify things like the length of output, or the justification of it, etc. The output format of %p is an exception to most of the standard printf codes in that it's output is implementation-dependent. | March 17, 2004, 12:31 AM |
Grok | I think their terminology is 'format specifiers'. | March 17, 2004, 2:59 AM |
Mephisto | Close enough. | March 17, 2004, 4:25 AM |
AC_Drkan | let me give you some code to see what it does. here its a combnation of different things just copy and paste it: [code]#include <stdio.h> void concat (char result[], char str1[], int n1, char str2[], int n2) { int i, j; /* copy str1 to result */ for ( i = 0; i < n1 ; ++i) result[i] = str1[i]; /* copy str2 to result */ for ( j = 0; j < n2 ; ++j) result[n1 + j] = str2[j]; } int string_length (char string[]) { int count = 0; while ( string[count] != '\0') ++count; return (count); } main() { void concat(char result[], char str1[], int n1, char str2[], int n2); int string_length (char string[]); char s4[81], s5[81], s6[81]; char s1[6] = {'T', 'e', 's', 't', ' ', '\0'}; char s2[7] = {'W', 'o', 'r', 'k', 's', '.', '\0'}; char s3[13]; int i; concat (s3, s1, 5, s2, 6); for ( i = 0; i < 11; ++i) printf ("%c\n", s3[i]); printf ("\n"); printf ("%i %i \n", string_length(s1), /* %c */string_length(s2)); printf ("Enter Text Here: "); scanf ("%s%s%s", s4, s5, s6); /* %s */ printf ("\ns1 = %s\ns2 = %s\ns3 = %s\n\n", s4, s5, s6); printf ("\aSYSTEM SHUT DOWN IN FIVE MINUTES!!! \n"); } [/code] Zak's edit: learn to use code tags please - and why on earth did you write your own versions of strlen and strcat? there are already perfectly good functions to perform concatenation and length determination | March 17, 2004, 4:28 PM |
iago | Yes, and the standard strlen and strcat are much more efficient. | March 19, 2004, 2:06 PM |
Skywing | I don't think his concat() will null terminate it with the arguments he gave. | March 19, 2004, 7:18 PM |
iago | You're right. Why would you ever need to specify lengths, anyway? int i = 0, j = 0; while(str1[i]) result[i] = str1[i++]; while(str2[j]) result[i++] = str2[j++]; result[i] = '\0'; Although the standard strcat() will still work better. | March 19, 2004, 7:24 PM |
Eibro | I wonder what a strcat looks like. Meow. | March 20, 2004, 1:00 AM |
Yoni | [quote author=Eibro link=board=30;threadid=5824;start=0#msg50519 date=1079744409] I wonder what a strcat looks like. Meow. [/quote] [img]http://www.dogbreedinfo.com/images7/maggietigger_the_cat.jpg[/img] | March 20, 2004, 4:20 PM |