Hi all,

I just get stuck with this kind of simple problem. Such a novice i am.
Could you help me guys.:$

I try to built the code and for the first procedure i should open first the file. The file which i should opened its depend on the input i gave. Compiling it's OK. But It's not working. There no sign at all.

Here the code. (i am also attach kind of file i should open in this code)

#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>

main() 
{ 

    FILE *finput, *fopen();
    int i;
    char pfile[80];
    
	printf ("Type number of input (between 1 to 3): ");
    scanf ("%i", i);
    
    if (i = 1)
    pfile == "pf1";
    else if (i = 2)
    pfile == "pf2";
    else if (i = 3)
    pfile == "pf3";
   	else
   	 {printf ("Invalid Input, the number should between 1 to 3!!!");}
    
    
    finput = fopen(pfile, "r");
    	   
    if(finput==NULL) {printf("Error: can't open the file.txt\n");return 2;}
    else {printf("File opened successfully.\n");}      
	
    
    fclose(finput);
    system("pause");
	return(0);

	
}

Thank you in advanced

inC

Recommended Answers

All 3 Replies

Is this your first post? It isn't. Post source code in BB tag - click on # icon above the text area of message.

Had you compiled this code?

Well do you know what exactly you are doing or what you want to do ?

FILE *fopen(); // Why this ?

And what are you expecting the computer to display when you are just opening the file and closing it ?

finput = fopen(pfile, "r");

if(finput==NULL) {printf("Error: can't open the file.txt\n");return 2;}
else {printf("File opened successfully.\n");}

fclose(finput);

And why so much complexity?

char pfile[80];
printf ("Type number of input (between 1 to 3): ");
scanf ("%i", i); // Error here in scaning (no &)
if (i = 1)
pfile == "pf1";
else if (i = 2)
pfile == "pf2";
else if (i = 3)
pfile == "pf3";
else
{printf ("Invalid Input, the number should between 1 to 3!!!");}
finput = fopen(pfile, "r");

The complete thing above can be done just by:

char pfile[80];
printf ("Type number of input (between 1 to 3): ");
scanf ("%i",&i);
sprintf(pfile,"pf%d",i);
finput=fopen(pfile,"r");

My mistake with *fopen()...
yes i compiled it..not error message appears..

phew..thanks..guyss

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.