我是一个帮助翻译文字的助手。
我写的程序是这样的:
我真的很新于编程,在为暑期项目努力思考了一周后,我真的需要一些帮助!
我试着读取一个很长的文本文件,它只是一个长字符串(注意:不是实际的编程字符串),然后将每个字母放到网格中的相应位置(程序的目标最终是解决一个单词查找问题)。到目前为止,我想出了下面的程序,它似乎没有产生一个网格,而只是重复打印文本文件,并在其前面加上以下内容:
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510
{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;}
\paperw11905\paperh16837\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720
\f0\fs24 \cf0
我写的程序是这样的:
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
int main()
{
int i,j;
char myarray[26][26],x;
FILE *myfile;
for (j=0; j<26; j++) //initialise array elements all to zero
{
for (i=0; i<26; i++)
{
myarray[i][j]=0;
}
}
myfile=fopen("*redacted*","r");
if (myfile!=NULL) //check file actually opened
{
for (i=0; i<26; i++)
{
for(j=0; j<26; j++)
{
fscanf(myfile,"%c",&x); //read the values in
myarray[i][j]=x;
}
}
// data is now in the array called myarray
fclose(myfile);
}
else
{
printf("File not found");
}
for(i=0;i<26;i++)
{
for(j=0;j<26;j++)
{
printf("%c",myarray[i][j]);
}
}
}
感谢您能提供的任何帮助
myarray
对象(变量)。 - user529758