0
#include<stdio.h>
int main()
{
        char *arg[10],*c;
        int count=0;
        FILE *fp,*fq;
        printf("Name of the file:");
        scanf("%s",arg[1]);
        fp=fopen(arg[1],"w");
        printf("\t\t%s",arg[1]);
        printf("Input the text into the file\n");
        printf("Press Ctrl+d to the stop\n");
        while((*c=getchar())!=EOF)
        {
                fwrite(c,sizeof(char),1,fp);
                count++;
        }
        return 0;
}
4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by untio
0

You never allocate any space for the char pointer arg[1] . You could either call a function like malloc and dynamicly allocate space for that c-string, or you could declare the c-string to the stack, like char arg1[100]; .

0

May be you may compare your code with this one:

#include<stdio.h>
int main()
{
        char arg[50];
        int c;
        int count=0;
        FILE *fp;
        printf("Name of the file:");
        scanf("%s",arg);
        fp=fopen(arg,"wt");
        printf("\t\t%s",arg);
        printf("Input the text into the file\n");
        printf("Press Ctrl+Z and Return on windows to the stop\n");
        while((c=getchar())!=EOF)
        {
                fputc(c, fp);
                count++;
        }
        fclose(fp);
        return 0; 
}

You will note some important diferences.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.