Click here to Skip to main content
15,887,585 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: turbo c codes.. need help Pin
CPallini9-Oct-09 12:18
mveCPallini9-Oct-09 12:18 
AnswerRe: turbo c codes.. need help Pin
theCPkid9-Oct-09 22:48
theCPkid9-Oct-09 22:48 
GeneralRe: turbo c codes.. need help Pin
Tabang10-Oct-09 6:13
Tabang10-Oct-09 6:13 
GeneralRe: turbo c codes.. need help Pin
Tabang10-Oct-09 6:58
Tabang10-Oct-09 6:58 
GeneralRe: turbo c codes.. need help Pin
theCPkid10-Oct-09 15:50
theCPkid10-Oct-09 15:50 
QuestionFIle handling. turbo c Pin
Tabang9-Oct-09 6:53
Tabang9-Oct-09 6:53 
QuestionRe: FIle handling. turbo c Pin
David Crow9-Oct-09 7:50
David Crow9-Oct-09 7:50 
AnswerRe: FIle handling. turbo c Pin
CPallini9-Oct-09 12:08
mveCPallini9-Oct-09 12:08 
No surprise, since the latter program is a bad porting of the former one. Try
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void main()
{
	FILE *fp, *fpi;
	int a;
	char base[2];

	int i,x;
	char str[50];
	/*={'I','V','X','L','C','D','M'};*/

	char c;
	int counter=0;
	fpi = fopen("input.txt","r");
	fp = fopen("output.txt","a+");
	if (!fp || !fpi) return;
	while (!feof(fp))
	{
		//clrscr();
		if(counter!=0)
		{
			for(i=0;str[i]!=NULL;i++)
				str[i]=' ';
		}
		if (fscanf(fpi, "%d",&a) != 1) break;
		fprintf(fp,"\n\nHindu Arabic: %d",a);
		

		if(a<=0 || a>=4000)
		{
			printf("out of range");
			fprintf(fp,"\t\tOut of range!!!!");
			goto exit;

		}
		i=0;
		while(a>0)
		{
			if(a>=1 && a<4)
			{	
				base[0] = 'I'; base[1] = ' ' ; a = a-1;
			}
			else if(a>=4 && a<5)
			{	
				base[0] = 'I'; base[1] = 'V'; a = a-4;
			}
			else if(a>=5 && a<9)
			{	
				base[0] = 'V'; base[1] = ' '; a = a-5;
			}
			else if(a>=9 && a<10)
			{	
				base[0] = 'I'; base[1] = 'X'; a = a-9; 
			}
			else if(a>=10 && a<40)
			{	
				base[0] = 'X'; base[1] = ' '; a = a-10; 
			}
			else if(a>=40 && a<50)
			{	
				base[0] = 'X'; base[1] = 'L'; a = a-40;
			}
			else if(a>=50 && a<90)
			{	
				base[0] = 'L'; base[1] = ' '; a = a-50; 
			}
			else if(a>=90 && a<100)
			{	
				base[0] = 'X'; base[1] = 'C'; a = a-90; 
			}
			else if(a>=100 && a<400)
			{	
				base[0] = 'C'; base[1] = ' '; a = a-100; 
			}
			else if(a>=400 && a<500)
			{	
				base[0] = 'C'; base[1] = 'D'; a = a-400; 
			}
			else if(a>=500 && a<900)
			{	
				base[0] = 'D'; base[1] = ' '; a = a-500; 
			}
			else if(a>=900 && a<1000)
			{	
				base[0] = 'C'; base[1] = 'M'; a = a-900; 
			}
			else if(a>=1000 && a<4000)
			{	
				base[0] = 'M'; base[1] = ' '; a = a-1000; 
			}
			else 
			{	
				base[0] = ' '; base[1] = ' '; 
			}
			str[i]=base[0];
			str[i+1]=base[1];
			i+=2;
		}
		
		str[i]='\0';
		
		fprintf(fp,"\t\tRoman Numeral:");
		for(i=0;str[i]!='\0';i++)
		{
			if ( str[i] != ' ')
			{
				fprintf(fp,"%c",str[i]);
			}
		}
exit:
		counter++;
	}

	fclose(fp);
	fclose(fpi);
}



BTW: In both programs you missed to zero-terminate the string str.

Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

modified on Friday, October 9, 2009 6:16 PM

GeneralRe: FIle handling. turbo c Pin
Tabang9-Oct-09 12:48
Tabang9-Oct-09 12:48 
GeneralRe: FIle handling. turbo c Pin
Tabang9-Oct-09 12:57
Tabang9-Oct-09 12:57 
QuestionHow can i convert a .doc file to .html Pin
SNArruda9-Oct-09 5:22
SNArruda9-Oct-09 5:22 
AnswerRe: How can i convert a .doc file to .html Pin
Code-o-mat9-Oct-09 6:37
Code-o-mat9-Oct-09 6:37 
AnswerRe: How can i convert a .doc file to .html Pin
David Crow9-Oct-09 7:28
David Crow9-Oct-09 7:28 
QuestionHow to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 4:20
moh.hijjawi9-Oct-09 4:20 
AnswerRe: How to update a field in an DB using MFC Pin
David Crow9-Oct-09 4:48
David Crow9-Oct-09 4:48 
GeneralRe: How to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 5:33
moh.hijjawi9-Oct-09 5:33 
QuestionRe: How to update a field in an DB using MFC Pin
David Crow9-Oct-09 5:38
David Crow9-Oct-09 5:38 
AnswerRe: How to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 5:46
moh.hijjawi9-Oct-09 5:46 
QuestionSearching item in second column list control using find function Pin
Le@rner9-Oct-09 2:37
Le@rner9-Oct-09 2:37 
QuestionRe: Searching item in second column list control using find function Pin
David Crow9-Oct-09 3:37
David Crow9-Oct-09 3:37 
QuestionHow to remove C4389 Pin
KASR19-Oct-09 0:26
KASR19-Oct-09 0:26 
AnswerRe: How to remove C4389 Pin
sashoalm9-Oct-09 0:30
sashoalm9-Oct-09 0:30 
AnswerRe: How to remove C4389 Pin
transoft9-Oct-09 2:41
transoft9-Oct-09 2:41 
QuestionBG color for popup dialogs Pin
hellogany8-Oct-09 23:16
hellogany8-Oct-09 23:16 
AnswerRe: BG color for popup dialogs [modified] Pin
Hristo-Bojilov8-Oct-09 23:58
Hristo-Bojilov8-Oct-09 23:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.