1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include <stdio.h>
#include <string.h>
//Variables
FILE *fo, *fp;
int line, row, col, ch, row2, col2;
char inFileName[101], outFileName[105], streamin[50000], word[21], wordArray[2501][21], textArray[50][50][21], *readPoint=streamin;
//Prototypes
void openInFile(char inFileName[]);
void openOutFile(char outFileName[]);
void reader(char inFileName[]);
void debug(void);
void toWord(void);
int main(void)
{
//takes in input file and will repeat until file is able to be opened
do
{
//take in file name, call it inFileName
printf("\nPlease enter the name of the file you wish to use: ");
fgets(inFileName, sizeof(inFileName)-1, stdin);
//removes newline character taken in by fgets
for(row=0;row<101;row++)
if(inFileName[row]=='\n')
inFileName[row]='\0';
//attempts to open file
openInFile(inFileName);
if(fp==NULL)
printf("\nFile cannot be opened, please try again.");
}while(fp==NULL);
//copy and add ".out" to file name and make outFileName
strncpy(outFileName, inFileName, sizeof(inFileName));
strcat(outFileName, ".out");
//read input file, and split into textArray.
reader(inFileName);
//Optional debug function here
//debug();
toWord();
return 0;
}
//Function for opening input file
void openInFile(char inFileName[])
{
fp=fopen(inFileName, "r");
}
//Function for opening output file
void openOutFile(char outFileName[])
{
fo=fopen(outFileName, "r+");
}
//Function to turn input file into textArray
void reader(char inFileName[])
{
//Read file and turn into big string
while((ch=fgetc(fp)) != EOF)
{
streamin[col]=ch;
col++;
}
fclose(fp);
//Turn string into big array. If \n is encountered, new line. Improprer entries removed and only words remaining
row=0;
line=0;
for(row=0;row<51;row++)
for(col=1;col<22;col++)
{
if(*readPoint=='\n')
{
++readPoint;
line++;
row=0;
break;
}
if(*readPoint==' '
||*readPoint<=64
||*readPoint>=123
||*readPoint==91
||*readPoint==92
||*readPoint==93
||*readPoint==94
||*readPoint==95
||*readPoint==96)
{
++readPoint;
break;
}
textArray[line][row][col]= *readPoint;
++readPoint;
}
}
//Print out reformatted data in textArray
void debug(void)
{
for(line=0;line<51;line++)
for(row=0;row<51;row++)
for(col=1;col<22;col++)
if(textArray[line][row][col]!='\0' && textArray[line][row][col]!='\n' && textArray[line][row][col]!=' ')
printf("%c", textArray[line][row][col]);
}
//Problem Is here, cannot wrap my head around this logic
void toWord(void)
{
for(row=0;row<20;row++)
{
for(col=0;col<22;col++)
word[col]=textArray[line][row][col];
for(row2=0;row2<25;row++)
for(col2=0;col2<22;col++)
if(word[col2]!=wordArray[row][col2])
{
wordArray[row2][col]=word[col];
}
else
{
break;
}
}
//Trying to print out unique word list here
for(row2=0;row2<2501;row2++)
for(col=0;col<22;col++)
printf(" %d%d %c", row2,col,wordArray[row2][col]);
}
|