473,624 Members | 2,072 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 1703
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
1237
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, but the main difference being that in my code I simply give the stream reader the path to my file, where as in the example they opened the text file, held it in an object, then fed that to the stream reader.
1
3118
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 file in notepad. I am not able to resolve it. Can you please help me with code how to do it? I have spent days after days seraching Web, books with no luck. I am a newbie in .net. Thanks a lot Hope someone would be kind enough to provide me a...
3
1608
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 an array...namea and 8888 and 1234.99 would be three arrays thanks
13
39871
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 notepad so the user can see what was built. I cannot for the life of me figure out how to get the text file to open up in notepad on the screen. All the processes I have tried opens the file into the filestream again.
13
1519
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 get an error in my program after the file has been opened once, it gives me a message saying "System.IO.IOException: File already open." FileOpen(1, "C:\xmltrips.txt", OpenMode.Output, OpenAccess.Write)
1
3679
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
1956
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 will do some calcuation the it is written to a text file called "result.txt". Then i would like it to open the text file automatically after the calculation instead of i going to the folder to open it to view. Anyone know how to do so? Thanks
1
5812
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 file.. does anyone know how i can get it to write meow on the line after "putwordhere"???????????? #include <iostream> #include <fstream> #include <string> using namespace std; int main(){ string line; string searchage;
8
1972
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 kind). The filename gets found and placed into a variable named I'm using python to find the text files, and a .ezt template to display the list of the files. But I can't figure out how to read the contents of the file, and display it...
2
1966
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
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8335
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
8475
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
7159
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...
0
5563
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
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
2
1482
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.