0

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();

}
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by John A
0

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.

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.