ofstream f;
		char c;		
		f.close();
		f.open(s.c_str(),ios::out);
		if(f.is_open())	{
		cout<<"Press <q> to save file";
		char *text;
		int count=0,count1;
		
		while(1)
		{	system("stty raw -echo");	
			cin>>c;
			cout<<c;
			system("stty cooked echo");	
			text[count]=c;
			++count;			
                
                if(c=='q')
			{
                 	text[count]='\0';
                        while (text[count1]!='\0')
				f.put(text[count1++]);
			f.close();
	                break;
                        }
}

please help me out in this syntax i was not able to write data in file
Why this code gives segmentation fault
how i can resolve this problem

char *text;

You have an uninitialized pointer here, and a few lines down, you try to store something in it. Allocated memory for your C-string using new.

Why do you close the file before you open it in the beginning of the code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.