473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Re-arranging programm

Hi!
I'm writing a small C program to post process a huge txt file produced by a CFD software.

The CFD creates a "from.txt" file, in which every line contains many parameters calculated by it.
I need to copy the lines that contain the information i need to another "to.txt" files.

The problem is that I don´t know how to go thru the lines of the from.txt.
Once i know how to go thru them it wouldn't be that hard to write the rest of the program.

I working on something like...

fp=fopen(filename,"r");
while(c == getchar());
if (c == \n);

... but i have no idea how to go on...

I`m a newbie in this world... hope learn a lot from you all!
Jul 3 '07 #1
3 1188
sicarie
4,677 Expert Mod 4TB
After you open the file, I would recommend using a test more like != EOF in your while loop, and then you can use getline() to pull the whole line in, and then parse it as a string - probably a bit easier than looking at the individual characters.

http://www.cplusplus.com/
http://www.cplusplus.com/reference/string/getline.html
http://www.cplusplus.com/doc/tutorial/files.html

PS - are you specifically constrained to C, or are you able to use C++ as well? Getline and EOF are built into C, so you should be able to use them, but the tutorials given are in C++, so you'll have to modify them a bit...
Jul 3 '07 #2
Silent1Mezzo
208 100+
Hi!
I'm writing a small C program to post process a huge txt file produced by a CFD software.

The CFD creates a "from.txt" file, in which every line contains many parameters calculated by it.
I need to copy the lines that contain the information i need to another "to.txt" files.

The problem is that I don´t know how to go thru the lines of the from.txt.
Once i know how to go thru them it wouldn't be that hard to write the rest of the program.

I working on something like...

fp=fopen(filename,"r");
while(c == getchar());
if (c == \n);

... but i have no idea how to go on...

I`m a newbie in this world... hope learn a lot from you all!
If the line needs to contain something specific you could use strstr()

Expand|Select|Wrap|Line Numbers
  1. if(strstr(str1, str1) != NULL)
  2.          //Theres a match
  3.  
If theres a match then it means that your information is in that line.
Jul 3 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
You can use the getline() function to read one line of text at a time. You will need to declare a char array to hold this line of text.

You use fwrite() to write the line toi another file.

Start your research with getline() and find out how to use FILE*.

Any C textbook will have your problem as an example.
Jul 3 '07 #4

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

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
1
by: balzano_1 | last post by:
Hi, im trying to upload a file from a client (windows) to an ftp server (linux), i deciede to use some of php`s functions to connect and authenticate etc.. i only wish to put a file on the server,...
1
by: Muttly | last post by:
Hey all. I'm trying to upload multiple files. I'm using the chm file from php.net to help me figure it out. I also checked online and say theres a problem with the file. Anyway My html looks like...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
0
by: chris | last post by:
I'm writing a small app to help me learn more about cryptography. All it does is encrypt all of the files in directory A, and put the encrypted versions of the files in directory B. It then...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
1
by: Mika M | last post by:
I have made Setup and Deployment Project for my application. This application uses couble of Crysral Report .rpt -files, so I included following into Setup and Deployment Project ... -...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.