|
|
#include <stdio.h>
#include <memory.h>
void
main( int argc, char *argv[] )
{
}
| |
|
|
|
#include <stdio.h>
#include <memory.h>
void
main( int argc, char *argv[] )
{
|
FILE *fp;
fp = fopen( argv[1], "rt" );
if ( fp == NULL ) {
exit(1);
}
fclose( fp );
| |
|
}
|
(3) テキストファイルを1行づつ最後まで読み込む |
|
#include <stdio.h>
#include <memory.h>
void
main( int argc, char *argv[] )
{
FILE *fp;
fp = fopen( argv[1], "rt" );
if ( fp == NULL ) {
exit(1);
}
|
char buffer[4096];
while( 1 ) {
fgets( buffer, 4096, fp );
if ( feof( fp ) ) {
break;
}
}
| |
|
fclose( fp );
}
|
|
#include <stdio.h>
#include <memory.h>
void
main( int argc, char *argv[] )
{
FILE *fp;
fp = fopen( argv[1], "rt" );
if ( fp == NULL ) {
exit(1);
}
char buffer[4096];
|
int line;
int len;
int i;
int TargetLen;
TargetLen = strlen( argv[2] );
line = 0;
| |
|
while( 1 ) {
fgets( buffer, 4096, fp );
if ( feof( fp ) ) {
break;
}
|
line++;
len = strlen( buffer );
for( i = 0; i < len; i++ ) {
if ( memcmp( buffer+i, argv[2], TargetLen ) == 0 ) {
printf( "%d : %s", line, buffer );
break;
}
}
| |
|
}
fclose( fp );
}
|
|
#include <stdio.h>
#include <memory.h>
void
main( int argc, char *argv[] )
{
FILE *fp;
fp = fopen( argv[1], "rt" );
if ( fp == NULL ) {
exit(1);
}
char buffer[4096];
|
char out[80];
int i,j,len;
| |
|
while( 1 ) {
fgets( buffer, 4096, fp );
if ( feof( fp ) ) {
break;
}
|
len = strlen( buffer );
j = 0;
for( i = 0; i < len; i++ ) {
if ( buffer[i] != ',' ) {
out[j] = buffer[i];
j++;
}
else {
out[j] = 0x00;
printf( "%s\n", out );
j = 0;
}
}
j--;
out[j] = 0x00;
printf( "%s\n", out );
| |
|
}
fclose( fp );
}
|
|