How can I iterate over the individual characters of a string and copying them one by one to a struct. (in other words, I want to copy char by char into a struct member until a flag is triggered, then move to the next member of the struct i)
For instance I want to do:
Output:Code:#include <stdio.h> #include <stdlib.h> #include <string.h> struct account { char *name; }; int main () { struct account *acct; acct = malloc (40 * sizeof (struct account)); char *str = "Hello World"; char *a = str; char *copy; int i = 0; while (*a != '\0') { acct[i++].name = *a+1; // ?insert 2 char per member a++; } for(i = 0; i<6; i++) printf("%s\n",acct[i].name); }
acct[0].name = "He"
acct[1].name = "ll"
acct[2].name = "o "
...