Prob.
#include <stdio.h>
int main()
{
char listOfCharacters[50];
int num = 8675309;
sprintf(listOfCharacters, "%d" , num);
printf("Our list of characters are : %s",listOfCharacters);
return 0;
}
In this , i didnt understand the square bracket part in char - whats the use of it
and what does 'sprintf' do , %s - what is this aswell .
Thanks in advance .
so 50 is string lengh? or something else
by saying
char listOfCharacters[50];
you are telling the compiler that
listOfCharacters is an array of char types that will hold up to 50 characters.
in c and c++ the %s, %d are all placeholders for string or digit data - revise the syntax from the C videos
(http://www.wibit.net/sites/wibit.net/files/programminginc_-_04_-_output_to_the_console.pdf)
the sprintf loads the digits of the int into the character array. The printf then prints it.
Cheers,
cbrad.)
Thanks a lot . One last question , what all can i do with sprintf . i am not clear about it,havent seen any discussion so far on it in videos .
Great question! This is something that we didn't cover very well in our course. Not exactly sure why we overlooked this.. Perhaps we should go back and add it...
sprintf is great and it is often used in a lot of languages. Programmers will call this "S-Print-F" or "Sprint-F" of "String Print-F", and it is used as a String Formatter. You can store a string format result into a character array instead of printing to STDOUT (like in printf). Check out this code:
#include <stdio.h>
int main() {
printf("%s %s", "Hey", "Buddy");
return 0;
}
Above we are using printf to send a format string of "%s %s" to STDOUT and replacing the %s with two params: "Hey" and "Buddy". Therefore, the command prompt will say:
Hey Buddy
Now, take a look at this code:
#include <stdio.h>
int main() {
char buffer[256];
sprintf(buffer, "%s %s", "Hey", "Buddy");
puts(buffer);
return 0;
}
Above we are using sprintf to store the exact same result into a char[], and then I am printing that result out to STDOUT using puts.
Does this answer your question?
ok thanks . Yes it does answer it.
how in ur code the syntax is highlighted while mine isnt?
If your browser supports it, our forums rich text formatter has an icon with a yellow highlighter. This is the Synrax Highlighter. Click on that, paste or type your code in the text box and it will be formatted just like mine!
i am on this place. i don't know why i am getting error " 'variable.exe' is not recognized as internal or external command, operable program or batch file".
any athor program work but i don't know why this is unable to run, and i notice that somtime when i put "\n" in program at that time it does not work and when i remove "\n" it work well. why ? any suggestion ?????
check to make sure your in the right directory and you spelled everything correctly. try typing "dir" in the command promt to see if your there otherwise just look for the executable in your search or just check the folder manually.
as far as the problem with newlines i couldnt say.
Hope this could be of some help
Forum Rules/Features
Welcome to the WiBit.net forums! Check out our terms and features:
Hot Topic(s)
Annoy your friends
Is this something you think someone else would enjoy? Is it not for you, but do you know someone who is down with this type of content? Well share away:
Tweet
The Blog
Don't Let XML Make You a Cheater
This blog is a reminder that cheating in software development can get you into big trouble. Sometimes developers get really really lazy, OR are pressured to write something using overly simplified data structures. Almost every time this happens you are bitten in the butt! Sometimes the problems show up immediately and other times it may take months or years (especially in integrated systems).
- 1 of 78
- ››

























the square brackets in the char are to make it a string not a single character and the %s is to print the string and sprintf..... I dont remember XD gotta review that part