![](/img/trans.png)
[英]Reading characters from a text file in c and storing in 2d array problems
[英]Reading characters from a text file and storing in a 2D array
愚蠢的问题,但我感到恐慌。 我将如何从文本文件(包括空格)中读取字符并将其存储在2D数组中。
我知道我需要使用一些涉及的东西(例如我有一个2D数组文件[50] [50])
while ((ch = fgetc(fp)) != EOF);
file[50][50] = characterWithinFile
任何帮助将不胜感激,因为我(令人惊讶地)知道在此之后我需要做什么。 谢谢
这是一些可以帮助您的代码
#include <stdio.h>
void main()
{
FILE *fopen(), *fp;
char c;
int i=0,j=0;
char file[50][50];
fp = fopen("file.txt","r");
c = getc(fp) ;
while (c!= EOF)
{
file[i][j]=c;
j++;
c = getc(fp);
if(j==50){
i++;
j=0;
}
}
fclose(fp);
}
如果您的文字超过2500个字符,请选择大于50的数字!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.