I am trying to print each char
in s
array one at a time. The program I have printed all the letters after the defined index in the array.
The problem I am facing is after that the user inserts the phrase then it is allocated. How do you call letters from the string using pointers?
Can you use strtok
to split this string, I tried setting the delim
to "" got no output.
In other word make it a list like a Python split()
.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
char *s;
s = malloc(1024 * sizeof(char));
scanf("%[^\n]", s);
s = realloc(s, strlen(s) + 1);
//printf("%s \n", s);
for (int i = 0 ; i <strlen(s); i++){
printf("%s \n", &s[i]);
}
return 0;
}