-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteDataToFile.c
More file actions
39 lines (33 loc) · 1.03 KB
/
writeDataToFile.c
File metadata and controls
39 lines (33 loc) · 1.03 KB
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
#include <stdio.h>
void writeDataToFileMenu(char strings[100][51],int *arrayLength,int *maxStringLength)
{
//used the same technique in print array to screen
if (*arrayLength == 0)
printf("No Items Found!\n");
else
{
char fileName[21];
printf("What's The Name Of The File You Want To Save Data To ? \n");
scanf("%s",fileName);
FILE *out;
out = fopen(fileName,"w");
char currentLetter = strings[0][0];
int i=0;
fprintf(out,"%c:\n",toUpperCase(currentLetter));
while (i<*arrayLength)
{
if (toUpperCase(currentLetter) == toUpperCase(strings[i][0]))
{
fputs(strings[i++],out);
fputs("\n",out);
}
else
{
currentLetter = toUpperCase(strings[i][0]);
fprintf(out,"%c:\n",toUpperCase(currentLetter));
}
}
fclose(out);
printf("Names Were Written To File \"%s\" Successfully!\n",fileName);
}
}