Reputation: 217
int
cycle(n) {
char *s3 = "Different";
int i, length;
length = strlen(s3)
printf("%s\n", s3);
for (i=0; i<length; i++) {
printf("%s\n", &s3[i]);
}
return 0;
}
I'm trying to print out one character at a time on each newline however the output looks like this -
C: Different
C: ifferent
C: fferent
ect.
How do I make it just output one character at a time? Example (C: D, C:i, C:f, ect.)
Upvotes: 2
Views: 1923
Reputation: 25621
#include <stdio.h>
for (int i = 0; i < strlen(s3); i++) {
printf("%c\n", s3[i]);
}
Upvotes: 2
Reputation: 24375
You should change:
printf("%s\n", &s3[i]);
to
printf("%c\n", s3[i]);
The former prints a string
while the latter prints a char
.
Upvotes: 4