ファイル入出力

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
blue

ファイル入出力

#1

投稿記事 by blue » 15年前

「実行すれば、下記の内容をファイルhelloworld.txtとして出力するプログラムを作成せよ




Hellow world!
When I woke up this mornig,I found many people in my room
What's up?? : -0

」という問題をやっているのですが、うまくいきません。

16行目が「called object is not a function」というエラー文がでます。@の部分を消してコンパイルすると通るが、実行すると「ファイルが表示されません」と表示されます。どうすればよいでしょうか?

自分が作ったソース
#include <stdio.h>
#include <stdlib.h>

int main(void){
char greeting[100];
char talk1[100];
char talk2[100];
FILE *fpin,*fpout;

fpin = fopen( "helloworld.txt", "r");
if(fpin == NULL)
{
printf("ファイルが開けません\n");
exit( EXIT_FAILURE );
}
if((fpout = fpin("out.dat", "w")) == NULL){ /* 出力ファイルオープン */ //@
printf("ファイルが作成できません\n"); //@
exit( EXIT_FAILURE ); /* 強制終了 */ //@
} //@

while( fscanf( fpin," %s\n %s\n %s", &greeting,&talk1,&talk2) !=EOF)
{
fprintf( fpout, "Hellow world!!\n", greeting);
fprintf( fpout, "When I woke up this mornig,I found many people in my room\n", talk1);
fprintf( fpout, "What's up?? : -0", talk2);
}

fclose( fpin );
fclose( fpout );

return EXIT_SUCCESS;
}

Blue

Re:ファイル入出力

#2

投稿記事 by Blue » 15年前

>fpin
って関数あるんでしょうか?
fopenじゃなくて?

blue

Re:ファイル入出力

#3

投稿記事 by blue » 15年前

fopenに直したらコンパイルは通りました。しかし、ファイルが開けませんと表示されます。
どこを直せばよいでしょうか?

Blue

Re:ファイル入出力

#4

投稿記事 by Blue » 15年前

>fpin = fopen( "helloworld.txt", "r");
このファイルがあるのかどうかということ。

というか
>実行すれば、下記の内容をファイルhelloworld.txtとして出力するプログラムを作成せよ
と全然違うことやっているのでは?
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE* fpout;
    
    fpout = fopen("helloworld.txt", "w");
    if (fpout == NULL)
    {
        printf("ファイルが開けません\n");
        return EXIT_FAILURE;
    }
    
    fprintf(fpout, "Hellow world!!\n");
    fprintf(fpout, "When I woke up this mornig,I found many people in my room\n");
    fprintf(fpout, "What's up?? : -0"); 
    
    fclose(fpout);
    
    return EXIT_SUCCESS;
}

blue

Re:ファイル入出力

#5

投稿記事 by blue » 15年前

ありがとうございます。BLUEさんのいう通り全く違うことをしていたみたいです。やっとスッキリすることができました。


閉鎖

“C言語何でも質問掲示板” へ戻る