[Code]How to parse some text from a file to another file

on

Code in C:

If we download address book from SKYPE then we want to separate only the skype ids then we can do this simple code:

###################################################################

#include “stdio.h”

#include “string.h”

#include “conio.h”

int main()

{

static const char filename[] = “skypeDownloaded_IDS.txt”;

FILE *outputFile = fopen(“save_all_id.txt”, “w”);

char compareLine []= “X-SKYPE-USERNAME:”;

bool flag = 0;

int i=0;

FILE *file = fopen ( filename, “r” );

if (outputFile == NULL)

{

printf(“Error opening file!\n”);

}

if ( file != NULL )

{

char line [ 80 ]; /* or other suitable maximum line size */

int lineLen= strlen(compareLine);

while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */

{

for(i=0; i<lineLen; )

{

if(compareLine[i]==line[i])

i++;

else break;

if(i==lineLen)

flag=1;

else flag=0;

}

if(i==lineLen)

{

fprintf(outputFile, “%s”, line);

}

}

fclose(outputFile);

fclose ( file );

}

else

{

perror ( filename ); /* why didn’t the file open? */

}

getch();

return 0;

}

####################################################################

Leave a Reply

Your email address will not be published. Required fields are marked *