Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char **data = NULL;
- unsigned dataSize = 0;
- while(1){
- char buffer[256] = { 0 };
- printf("Enter string: ");
- scanf("%255[^\n]", buffer);
- getchar();
- data = realloc(data, (++dataSize)*sizeof(char *));
- data[dataSize-1] = calloc(strlen(buffer)+1, 1);
- strcpy(data[dataSize-1], buffer);
- if (strcmp(buffer, "0") == 0){
- break;
- }
- }
- for(int i = 0; i < dataSize; ++i){
- if (strlen(data[i]) > 0)
- printf("[%d] -> %s\n", i, data[i]);
- else
- printf("[%d] empty\n", i);
- }
- for(int i = 0; i < dataSize; ++i){
- free(data[i]);
- }
- free(data);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement