I have to insert some quotation marks into a string. One “ after the sixth blank ond one “ befor the last
but one “ in the string (blank between “ and the last but one “). Mabe someone can help me, because
I’m not too familiar with C. I can use ANSI-C only.
The strings look like this:
217.3.189.72 - [27/Apr/2003:00:00:26 +0200] 200 277 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
217.3.189.72 - [27/Apr/2003:00:00:25 +0200] 200 277 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 902 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 197 GET /release_110d/config/messages_stlg.txt
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 2198 GET /release_110d/images/logo_applet_stlg.jar
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:24 +0200] 200 197 GET /release_110d/config/messages_stlg.txt
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.3.189.72 - [27/Apr/2003:00:00:24 +0200] 200 7339 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
The code I use to read/write input/output is
int main (int argc, char *argv[])
{
char rfilename [ NAME_MAX + 1 ];
char wfilename [ NAME_MAX + 1 ];
FILE *rfp, *wfp;
int i;
char str[ S_LEN ];
char *str_addr;
char *add_str = "\x22";
if ( argc == 3 )
{
strncpy ( rfilename, argv [ 1 ], NAME_MAX );
rfilename [ NAME_MAX ] = '\0';
strncpy ( wfilename, argv [ 2 ], NAME_MAX );
wfilename [ NAME_MAX ] = '\0';
}
else
{
fprintf (stderr, "Aufruf: %s inputfile outputfile\n", argv[ 0 ] );
return 1;
}
rfp = fopen ( rfilename , "rb" );
if ( rfp == NULL )
{
fprintf (stderr, "%s: Error opening %s for reading! \n", argv[ 0 ],rfilename );
perror ( "Reason" );
return EXIT_OREAD;
}
wfp = fopen ( wfilename , "wb" );
if ( wfp == NULL )
{
fprintf (stderr, "%s: Error opening %s for writing! \n", argv[ 0 ],wfilename );
perror ( "Reason" );
return EXIT_OWRITE;
}
{
while ( ( str_addr = fgets ( str, S_LEN, rfp )) != NULL )
{
fprintf(wfp, " %s ",str_addr);
}
if ( ferror ( wfp ) )
{
fprintf ( stderr, "%s: Error writing to file %s ! \n" , argv[ 0 ], wfilename );
perror ( "Reason" );
fclose ( rfp );
fclose ( wfp );
return EXIT_EWRITE;
}
}
fclose ( rfp );
fclose ( wfp );
return EXIT_OKAY;
}
but one “ in the string (blank between “ and the last but one “). Mabe someone can help me, because
I’m not too familiar with C. I can use ANSI-C only.
The strings look like this:
217.3.189.72 - [27/Apr/2003:00:00:26 +0200] 200 277 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
217.3.189.72 - [27/Apr/2003:00:00:25 +0200] 200 277 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 902 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 197 GET /release_110d/config/messages_stlg.txt
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:25 +0200] 200 2198 GET /release_110d/images/logo_applet_stlg.jar
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.83.13.3 - [27/Apr/2003:00:00:24 +0200] 200 197 GET /release_110d/config/messages_stlg.txt
HTTP/1.1 "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
217.3.189.72 - [27/Apr/2003:00:00:24 +0200] 200 7339 POST /xmlcom HTTP/1.1 "Mozilla/4.0
(compatible; MSIE 5.0; Win32)"
The code I use to read/write input/output is
int main (int argc, char *argv[])
{
char rfilename [ NAME_MAX + 1 ];
char wfilename [ NAME_MAX + 1 ];
FILE *rfp, *wfp;
int i;
char str[ S_LEN ];
char *str_addr;
char *add_str = "\x22";
if ( argc == 3 )
{
strncpy ( rfilename, argv [ 1 ], NAME_MAX );
rfilename [ NAME_MAX ] = '\0';
strncpy ( wfilename, argv [ 2 ], NAME_MAX );
wfilename [ NAME_MAX ] = '\0';
}
else
{
fprintf (stderr, "Aufruf: %s inputfile outputfile\n", argv[ 0 ] );
return 1;
}
rfp = fopen ( rfilename , "rb" );
if ( rfp == NULL )
{
fprintf (stderr, "%s: Error opening %s for reading! \n", argv[ 0 ],rfilename );
perror ( "Reason" );
return EXIT_OREAD;
}
wfp = fopen ( wfilename , "wb" );
if ( wfp == NULL )
{
fprintf (stderr, "%s: Error opening %s for writing! \n", argv[ 0 ],wfilename );
perror ( "Reason" );
return EXIT_OWRITE;
}
{
while ( ( str_addr = fgets ( str, S_LEN, rfp )) != NULL )
{
fprintf(wfp, " %s ",str_addr);
}
if ( ferror ( wfp ) )
{
fprintf ( stderr, "%s: Error writing to file %s ! \n" , argv[ 0 ], wfilename );
perror ( "Reason" );
fclose ( rfp );
fclose ( wfp );
return EXIT_EWRITE;
}
}
fclose ( rfp );
fclose ( wfp );
return EXIT_OKAY;
}