-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadFromFile.c
More file actions
31 lines (28 loc) · 968 Bytes
/
readFromFile.c
File metadata and controls
31 lines (28 loc) · 968 Bytes
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
#include <stdio.h>
void readFromFileMenu(char strings[100][51],int *maxStringLength,int *arrayLength)
{
int status,i=*arrayLength;
char fileName[21],line[51];
printf("Enter The Name Of The File You Want To Read From Followed by \".txt\": ");
scanf("%s",fileName);
FILE *in = fopen(fileName,"r");
/**
* asked the user to enter the name if the file he wanted to read from , then trimmed '\n' from each string I read
* and checked the maxStringLength while reading each line , and added items to the array and increased array length
*/
if (in)
{
while (fgets(line,50,in)!=NULL)
{
trimNewLineSymbol(line);
if (strLen(line)>*maxStringLength)
*maxStringLength = strLen(line);
strcopy(line,strings[i++]);
}
*arrayLength = i;
fclose(in);
printf("File Read Success!\n");
}
else
printf("File Not Found!\n");
}