mardi 10 novembre 2015

setting the if else condition for filtering data

i'm getting confused about the if else statement here. My source code is able to fscan the data from txt file and able to printf successfully.

My next step I like to do is setting a if else statement if the src is between 1-1024 and write that line to another txt file else if more than 1024 it should write to another txt file.

I been trying to combine both codes below but unable to get it work.

Read txt file and printf Source Code:

  do {
  test = fscanf(inFile, "%d:%d:%d:%d:", &src, &dest, &type, &port);//read line from file
    fgets(data, 100, inFile);
    printf("%d %d %d %d %s", src, dest, type, port, data);

    } while (test != EOF);

if (src >= 1 && src <= 1024){
}
else {

}
if (dest >= 1 && dest <= 1024){
}
else {

}

fclose(inFile); //must always close file once done

return 0;

Write into file Source Code:

outFile = fopen("data_1.txt", "rb+");
if (outFile == NULL)
{
    opened_in_read = 0;
    outFile = fopen("data_1.txt", "wb");
    if (outFile == NULL)
        there_was_error = 1;
}
if (there_was_error)
{
    printf("Disc full or no permission\n");
    return EXIT_FAILURE;
}
if (opened_in_read)
    printf("file in read mode.\n");
else
    printf("%d %d %d %d %s", src, dest, type, port, data);
return EXIT_SUCCESS;

Aucun commentaire:

Enregistrer un commentaire