Hi I'm having problems with the code in that everytime it iterates it replaces all the values of SendBack with the newly read in values from fgets!

    FILE *fp;
    char FileLoc[] = "123456-12345678.txt";
    char *SendBack[10];
    fp = fopen(FileLoc, "r");
    if (fp != NULL) {
        int x=0;
        while (fgets(BUFFER,20,fp)) {
            SendBack[x] = BUFFER;
            printf("%s",SendBack[0]);
            x++;
        }
    }
    else {
        perror("\n");
    }

Can somebody help please :)

you need to allocate new memory for the array.

SendBack[x] = malloc(strlen(BUFFER)+1);
strcpy(SendBack[x], BUFFER);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.