Ok guys, the purpose of my program is to read from a text file called orginal.txt containing names in the format:
Kyle Butler
Bob Jones
Nathan Moore
The program then takes these names one at a time and turns them into something like:
Kyle.Butler@emailaddress.com
This address is then stored line by line in a new text file called final.txt
problem is, i can't get it to work, it gives me a segmentation fault and does not even get to writing to final.txt
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void write(char line[100]);
int main()
{
FILE *fp;
fp = fopen("original.txt", "r+");
char line[100];
char mod[30]="@fakeemail.com\n";
while (fgets(line, 100, fp) != NULL){
int i;
for(i=0; i<100; ++i){
if(line[i]==' '){
line[i]='.';
}
if(line[i]=='\n'){
line[i]='\0';
}
strcat(line, mod);
}
FILE *fp2;
fp2 = fopen("final.txt", "a");
if (fp2 != NULL){
fputs(line, fp2);
fclose(fp2);
}
}
fclose(fp);
return 0;
}