Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main ()
- {
- long n;
- char temp[17]; // input buffer
- do
- {
- printf("How many strings?: ");
- fgets(temp, 16, stdin); // input
- n=strtol(temp,NULL,10); // convert to number
- }
- while (n==0); // failure gives 0 if they do not enter a valid integer
- char name[n][17];
- int i =0;
- for(i=0; i<n; i++)
- {
- printf("Input string number %d: ", i);
- do
- {
- fgets(temp, 16, stdin); // get input, max 16 chars
- char * where = strchr(temp,'\n'); // look for Enter
- if (where) // if got one
- *where=0; // replace by 0
- printf("Length of temp = %d temp = %s\n",strlen(temp), temp); // check what we've got
- }
- while (strlen(temp)<1); // in case they just press Enter
- strcpy(name[i], temp);
- }
- // check what we have:
- for(i=0; i<n; i++)
- {
- printf("%s\n",name[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment