i'm trying to write a program that reads a text from the user(keyboard) sentence by sentence and then prints the 'morse code' of them char bay char on a text file. I'm just testing it for the letter 'c' to start with, but it doesn't seem to be working well

#include <iostream.h>
#include <fstream.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
	fstream f1;
	f1.open ("doc1.txt", ios::in | ios:: out);



 char str[100];
cin.get(str,100);
int i=0;
while(str[i]){		
     cin>>str[i];
	 str[i]=(str[i]=='C'|| str[i]=='c')? 'blue': 'c';

	f1<<str[i];
	i++;
}


for(i=0; i<100;i++){
		

}

f1.close();

}

Recommended Answers

All 2 Replies

I found two problem.
1. if you use the following code to open a file, the file must exist before running your program.

f1.open ("doc1.txt", ios::in | ios:: out);

you can just use the default flag to open the file.

2.

str[i]=(str[i]=='C'|| str[i]=='c')? 'blue': 'c';

the type of str is 'char', it can only store one character, so you can not assign 'blue' to it.

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.