Thread: need help 4

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    6

    need help 4

    Hello again. Logic error

    my input file:
    !!Begin
    Source bserver:bmp_spool:the, Job 80c481ac001f6b07, Inst 80c481ac001f6b07
    Title BP Page 003 Date 070402 Black 3
    Action Finished Transmit, Ok Date Fri Apr 5 00:02:05 SGT 2002
    (2) Source Queue = Ajil_Tabloid
    (1) Destination = ajil:ajil1:bmp_spool:the
    (3) Dest Queue = Futuro Tabloid
    Transmitting to ajil:ajil1:bmp_spool:the
    !!End


    my source code:

    #include <stdio.h>
    #include <string.h>

    void main( void )
    {
    FILE *out;
    FILE *in;
    char line[80]=" ";
    char line2[8]="!!Begin";
    char line3[7]="";
    char line4[8]="!!End ";



    out=fopen("pxo.txt","w");
    in = fopen( "px.txt", "r" );
    while ((fgets(line,sizeof line,in)) != NULL)

    {


    printf( "%s", line);
    //line[strlen(line -1)]='\0';
    strncpy(line3,line,7);
    line3[7] = '\0';

    if (strcmp (line3,line4)== 0 )

    printf("Hello success\n");
    else
    printf("ooooo\n");


    }
    fclose( in );
    fclose( out );


    }


    when my program read last line "!!End" why it cannot say output
    "Hello success"?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    1.
    Use code tags.

    2.
    Use int main instead of void main.

    3.
    You declared

    char line3[7]="";

    So the last element is line3 [6], since the first element is line3 [0].

Popular pages Recent additions subscribe to a feed