473,508 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to open a file that realy exists

1 New Member
Hi there,

I'm newly here, and a beginner too.
I'm tryng to open a file that realy exists, but I cannot do that.
I'm using the Turbo C++ 3.0 compiler and my code is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <fcntl.h>
#include <io.h>

void ret_file()

{

char pathfile[20];
int hnd;
int c;
char a;
char t[1];

/* Try to open de file to read */

puts("Location File:");

do
{
a = getchar();
putchar(a);
itoa(a, t, 1);
strcpy(pathfile, t);
}
while (a != '\n');

printf("%s\n", *pathfile);

c = getch();

hnd = open(pathfile, O_TEXT);

printf("%d\n\n", hnd);

if (hnd == -1)
{
fprintf(stderr, "FILE NOT FOUND.\n");
return 0;
}
else
{
fprintf(stderr, "THATS OK -> THE FILE WAS FOUND.\n");
return 0;
}

}

If anybody here can helpe-me, I will be so greateful. ;-)
Sorry, but my english is not so good. :o
Aug 28 '06 #1
1 1938
Banfa
9,065 Recognized Expert Moderator Expert
replace

Expand|Select|Wrap|Line Numbers
  1. do
  2. {
  3.   a = getchar();
  4.   putchar(a);
  5.   itoa(a, t, 1);
  6.   strcpy(pathfile, t);
  7. }
  8. while (a != '\n');
  9.  
with

Expand|Select|Wrap|Line Numbers
  1. fgets(pathfile, sizeof pathfile, stdin);
  2.  
Look up fgets in your C/C++ manual/online, make sure you know why using itoa was not required.
Aug 28 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
3558
by: HolaGoogle | last post by:
hi all, can you please tell me what i should do to avoid session timeout when displaying my database info in my asp form (DisplayUserDatabase.asp)??? ** actualy it does load and display the...
1
1822
by: ids | last post by:
I have my own website and i want to use a mouse effect. My problem is that i use frames and when i put the javascript in the index.html like this: <html> <head> <meta name="keywords"...
7
17858
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
3
6332
by: grzybek | last post by:
Hi, I upload files to ma Web Server and then I can view those files as link. I'd like to be able to open those file in proper application on client PC. I want achieve the same result as though...
1
2252
by: PAM | last post by:
Hello I'm a newbie trying to open a connection to an Excel file in a deployed ASP .NET app and get the error Dim MyCommand As New OleDbCommand(mySelectQuery, MyConnection MyConnection.Open(
3
4838
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open...
2
4141
by: Peter S. | last post by:
I have an ASP.NET page that invokes a web control written in C#. What I want to do is (based on the session ID) display a certain spreadsheet that exists on a network drive. I want the webcontrol...
5
13836
by: colin | last post by:
Hi, Im looking for an open source http/web proxy server hopefully in c# there seems to be quite a few in python or java, but not come acros one in c# yet. is there anything around ? I wouldnt...
3
3162
kirubagari
by: kirubagari | last post by:
Would Like Ask Ques On How To Open Bonding.bin File In C++ Or In Visual Basic 6.actually The Data In The Binary File Have Been Corrupted And I Would Like To Know The Method How To Open The File That...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.