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

C / C++ / MFC

 
AnswerRe: turbo c codes.. need help Pin
Tabang9-Oct-09 12:59
Tabang9-Oct-09 12:59 
GeneralRe: turbo c codes.. need help Pin
theCPkid9-Oct-09 22:57
theCPkid9-Oct-09 22:57 
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 
can anyone help me on this code. im trying to input a hindu arabic number in a text file input.txt then it will output a conversion of that number into roman numeral... but the problem is it wont output the convertion.. the out put are trash characters.... but this worked when i was not inputting in a notepad .it worked when i was inputting in the running turbo c... here are my codes...... the first one is when the inputs are still in c and the other is in a .txt file....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
   {
    	FILE *fp;
	int a;
    	char base[2];

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

    	char c;
    	int counter=0;
	do
        	{
        	clrscr();
        	if(counter!=0)
            	{
            		for(i=0;str[i]!=NULL;i++)
            			str[i]=' ';
            	}
            	printf("\nEnter a number from 1 to 3999 only: ");
		scanf("%d",&a);
		fp = fopen("c:\output.txt","a+");
		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;
                }

             printf("\n\n\nThe number converted into roman numerals is: ");
	     fprintf(fp,"\t\tRoman Numeral:");
	     for(i=0;str[i]!=NULL;i++)

           {
            if(str[i]!=';' && str[i]!=' ')

		printf("%c",str[i]);
		fprintf(fp,"%c",str[i]);
           }
          exit:
          printf("\n\n\n\nPress any key to continue or space to exit... ");
		fclose(fp);
                c = getch();
                counter++;
            }while(c!=' ');

        } 


heres the one that inputs in a notepad and is not working


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
    {
    	FILE *fp,*fp2;
	int a;
    	char base[2];

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

    	char c;
    	int counter=0;
	do
        	{
        	clrscr();
        	if(counter!=0)
            	{
            		for(i=0;str[i]!=NULL;i++)
            			str[i]=' ';
            	}

		fp = fopen("c:\output.txt","a+");
		fp2= fopen("c:\input.text","r");

		while(!feof(fp)){

		    i=0;
		    fscanf(fp2,"%d",&a);
		    if(a>=0 && a<=3999)
                    {

		fscanf(fp2,"%d",&a);
		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;
                }

		fprintf(fp,"\nRoman Numeral:");

		for(i=0;str[i]!=NULL;i++)
                {
                if(str[i]!=';' && str[i]!=' ')

		  printf("%c",str[i]);
		  fprintf(fp,"%c",str[i]);

		}goto exit;
	      }
            exit:
            printf("\n\n\n\nPress any key to continue or space to exit..");
		fclose(fp);
                c = getch();
                counter++;
            }while(c!=' ');

        }


please can anyone help?
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 
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 

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.