[C language] If I enter 5 strings in a text file, is the text file 1 string? Is it five?

Asked 2 years ago, Updated 2 years ago, 72 views

Current code.

The appearance stored in the text file.

When you try to save a string in a text file to a string array How should I give the size of the string out of 1 or 5?

c string txt text-file

2022-09-20 21:54

1 Answers

Please refer to the code below.

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main()
{
    const char* n[5] = { "str","aa","bb","cc","dd" };
    FILE* fp = NULL;

    fp = fopen("Word.txt", "w");

    for (int i = 0; i < 5; i++)
    {
        fputs(n[i], fp);
        fputc('\n', fp);
    }

    fclose(fp);

    return 0;
}

The result


2022-09-20 21:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.