I've been reading a lot recently and I keep coming across %<letter> commands....
example....
[Pulled from 6.0 version of Greet Bot]
Send("%c%c%s\r\n%s\r\n", 0x03, 0x04, szLoginName, szPassword);
What exactly are these types of command, %c %s %d (may be others not sure)
Thanks for any and all help
- MBane_Agahnim
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.
Ok,
%c is individual characters like a, b, c, d
%s is a string of data like "i am cool"
Dan
Look up printf(), scanf() style formatting.
%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
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.
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.
I think their terminology is 'format specifiers'.
Close enough.
let me give you some code to see what it does.
here its a combnation of different things just copy and paste it:
#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");
}
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
Yes, and the standard strlen and strcat are much more efficient.
I don't think his concat() will null terminate it with the arguments he gave.
You're right. Why would you ever need to specify lengths, anyway?
int i = 0, j = 0;
while(str1)
result = str1[i++];
while(str2[j])
result[i++] = str2[j++];
result = '\0';
Although the standard strcat() will still work better.
I wonder what a strcat looks like.
Meow.
Quote from: Eibro on March 19, 2004, 07:00 PM
I wonder what a strcat looks like.
Meow.
(http://www.dogbreedinfo.com/images7/maggietigger_the_cat.jpg)