Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //code to take input of strings in an array of pointers
- #include <stdio.h>
- #include <strings.h>
- int main()
- {
- //suppose the array of pointers is of 10 elements
- char *strings[10],string[50],*p;
- int length;
- //proper method to take inputs:
- for(i=0;i<10;i++)
- {
- scanf(" %49[^n]",string);
- length = strlen(string);
- p = (char *)malloc(length+1);
- strcpy(p,string);//why use strcpy here instead of p = string
- strings[i] = p; //why use this long way instead of writing directly strcpy(strings[i],string) by first defining malloc for strings[i]
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement