473,498 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open a file (text file) from a specific location using C?

13 New Member
Hello fellow programmers, i'm having trouble opening a file from a specific location. Please help.

Expand|Select|Wrap|Line Numbers
  1. #include "maidcafe.h"
  2. ....
  3. char directory[80] = {"C:\\Users\\Public\\Documents\\Anime Notes\\Transaction\\"};
  4. char code[20];
  5. printf("Enter file name");
  6. gets(code);
  7. strcat(directory,code);
  8. system("start \"\" %s",directory);
  9.  
  10.  
i thought this would work, but it didn't xD. I got an error
Feb 2 '14 #1
3 1696
weaknessforcats
9,208 Recognized Expert Moderator Expert
Usually a file is opened using fopen.

Expand|Select|Wrap|Line Numbers
  1. FILE* fp;
  2. fp = fopen("C:\\etc...", "w+");
Feb 2 '14 #2
divideby0
131 New Member
If you're wanting some external program to use your file, then IIRC, system doesn't like the extra quotes and whatnot, so build your command string before calling the function. Use the short path name (the 8.3 notation) or you might try adding quotes around the entire finished path.

Expand|Select|Wrap|Line Numbers
  1. char directory[255] = "start \"c:\\......\\";
  2. // make sure directory has enough space
  3.  
  4. // get your file name
  5.  
  6. strcat(directory, code);
  7. strcat(directory, "\"");
  8.  
  9. system(directory);
  10.  
Another alternative is to use sprintf

Expand|Select|Wrap|Line Numbers
  1. char cmd[255] = { 0 },
  2.      directory[80] = "c:\\.....\\",
  3.      code[20] = { 0 };
  4.  
  5. // get required info
  6.  
  7. sprintf(cmd, "start \"%s%s\"", directory, code);
  8. system(cmd);
  9.  
Feb 2 '14 #3
animeprogrammer
13 New Member
thanks guys, you really helped me ;)
Feb 3 '14 #4

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

Similar topics

4
1233
by: Rob Meade | last post by:
Hi all, I was looking this evening for a quick sample of iterating through a text file to read it in line by line... I had already thrown something together myself which resembled the example,...
1
3111
by: RNDAS | last post by:
Hi, I have a DataGrid in my web page and there is a column in that grid which template column with linkButton. When Clicked the linkButton it should not refresh the page, rather it should open a...
3
1592
by: Jason | last post by:
Can someoneillustrate how I would open a text file that looks something similar to this: namea,8888,1234.99 nameb,8887,1242.50 and then after opening that file read each one of the values into...
13
39834
by: Chris Johnson | last post by:
I have what seems to be such a simple thing yet I cannot figure out how to do it. I am using a streamwriter to build a text file. At the end of the process I want to open that same text file in...
13
1503
by: Tony Girgenti | last post by:
Hello. I developed a web consuming windows application/form program with VS.NET 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1. Using this code to open a simple text file. If i...
1
3675
by: emm | last post by:
Hello, guyz! I need help on how to open a text file and read it line by line using VB6. What would be the codes? I have searched the forum and found one but it uses VB.net. :-( thanks!
1
1943
by: vincec | last post by:
Hi need some help from you guysin using visual C++. I am thinking of opening a text file after some calculation. For example, after i press the "calculation", then at the OnCalculation function, it...
1
5796
by: ecrovoyan | last post by:
I am trying to write a c++ program that reads through a text file and when i comes across a specific line it adds to that file. i have this code, but it doesnt write "meow" until the end of the text...
8
1959
by: Max Steel | last post by:
Hey gang, I'm new to python coding. I'm trying to find the simplest way to open a text file (on the same server) and display it's content. The text file is plain text (no markup language of any...
2
1959
by: vijendra singh | last post by:
I have created a notepad in c#. Now i want to open a text file in my notepad. but i dont know how to do that, can anybody help me?
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
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
7210
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
7381
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
5465
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,...
1
4916
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...
0
4595
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
3096
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
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.