473,796 Members | 2,720 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 1964
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
3587
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 database randomly....otherwise it's always runs into a session time out.... **Also when i save new account info (You'll notice that i've been asked to put a save button near each record...so, it's not one global save it's by record), i'd like to be...
1
1851
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" content="vacation"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>Vacation</title>
7
17880
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 able to encrypt and then decrypt data okay as in the following code: // encrypt the data // Encryptor enc = new Encryptor(EncryptionAlgorithm.TripleDes); byte key = Encoding.ASCII.GetBytes("0123456789012345");
3
6345
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 these files were saved locally on the client disk. For example .exe files - open window ( open , save or cancel possibility ) or for .doc files to open in Word application or save on disk.
1
2270
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
4858
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 a process of notepad on the server , but does not open the file in notepad. What am I doing wrong? can you show me how to do it please? What I am doing here is : I have datagrid data and when clicked on linkbutton (logFile), it finds the row...
2
4164
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 to open the spreadsheet using my log on credentials since they won't have priviliges to access their particular file from the network drive. BTW, I am guessing I will have to use HTTP as this file exists in a Sharepoint document library. I can...
5
13858
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 want to start from scratch, and most dont seem to do what I want. mainly to have more and easier control over what gets blocked etc. Colin =^.^=
3
3174
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 Contain In The Floopy Disk And Do Comparision So That The Corruted Data Can Be Changed Automaticaly.i Realy Need Ur Help Guys
0
10449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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 we have to send another system
3
2924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.