+ 1
hello guys, i got a problem on this code, it says no output this is C language the code is in the desc.
int main(){ int step; int u = "Anonymous"; int maxSteps = 10; for(step = 0; step <= maxSteps; step++){ printf("\nhey" + u + "you stepped" + step); } }
5 odpowiedzi
+ 2
You're more than welcome, Mikko. Best of luck to you in your learning!
+ 3
Why do you have a string literal assigned to an int variable? Store it in a char array instead. Also, use the placeholders in the 'printf' function instead.
https://code.sololearn.com/cAO9M9230POh/#c
#include <stdio.h>
int main(){
int maxSteps = 10;
char u[] = "Anonymous";
for(int step = 0; step <= maxSteps; step++) {
printf("hey %s, you stepped %d.\n", u, step);
}
}
:::: OUTPUT :::::
hey Anonymous, you stepped 0.
hey Anonymous, you stepped 1.
hey Anonymous, you stepped 2.
hey Anonymous, you stepped 3.
hey Anonymous, you stepped 4.
hey Anonymous, you stepped 5.
hey Anonymous, you stepped 6.
hey Anonymous, you stepped 7.
hey Anonymous, you stepped 8.
hey Anonymous, you stepped 9.
hey Anonymous, you stepped 10.
+ 2
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
^List of specifiers so you can see what each one does for you.
Using 'print format' function allows you to create your entire string without breaking it. This allows you to focus on an easily readable format for the string first; it's design. You use placeholders where the dynamic data will be populated by your variables, and then after the string, you specify (in order) the variables that'll fill in the placeholders.
In our example:
%s = string of characters
%d = decimal
+ 2
thank you so much
+ 1
sorry beginner on c, what is the meaning of putting that "%s" and "%d" i can't understand