GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jun-2004, 05:22
gwk gwk is offline
Awaiting Email Confirmation
 
Join Date: Jun 2004
Posts: 8
gwk is on a distinguished road
Question

Conversion from a data from line into a tabular form in C/C++


Hi all,
I have a text file let say it contains 7 lines. The first line contains the name of 20 cities separated by commas (or spaces). The remaining 6 lines carry corresponding data of the cities let say temprature, Humadity, latitude, longitude etc.
Now I want to reorganise this data in a tabular form in another .txt file.
I am familiar with fscane, fopen, fclose etc commands but I don't know How to put data in a tabular form.
I'll appreciate you prompt help in this regards.
GWK
Finland
  #2  
Old 08-Jun-2004, 08:42
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by gwk
Hi all,
I have a text file let say it contains 7 lines. The first line contains the name of 20 cities separated by commas (or spaces). The remaining 6 lines carry corresponding data of the cities let say temprature, Humadity, latitude, longitude etc.
Now I want to reorganise this data in a tabular form in another .txt file.
I am familiar with fscane, fopen, fclose etc commands but I don't know How to put data in a tabular form.
I'll appreciate you prompt help in this regards.
GWK
Finland

Hi Finland. Welcome to GIDForums.

What exactly do you mean by tabular format? Do you want your data seperated by tabs? Can you show a sample of what you want the text file to look like? From what I read you want something like 20 lines consisting of:
Code:
city_name temp humidity latitude longitude..... city_name temp ....

Is that correct?
  #3  
Old 08-Jun-2004, 09:30
gwk gwk is offline
Awaiting Email Confirmation
 
Join Date: Jun 2004
Posts: 8
gwk is on a distinguished road

Conversion from a data from line into a tabular form in C/C++


Hi dsmith,
Thank you very much for your prompt reply.
By tabular I meant writing data in Columns and rows form (in a table)

The first row of Table contains parameters names and the 2nd and onward rows carry the coresponding values e.g.

---Table statrs----
__________________________________________________ ___
city_name temp humidity latitude longitude.....
__________________________________________________ ___
Helsinki 25 xx xv bv
__________________________________________________ ___
Paris 30 .. .. ..
__________________________________________________ ___
London 31 .. .. ..
__________________________________________________ ___
NY 35 .. .. ..
__________________________________________________ ___
.. .. .. .. ..
__________________________________________________ ___
.. .. .. .. ..
__________________________________________________ ____


Is it possible at all to arrange data in tables in .txt files. Or any other alternative for output files?









city_name temp ....


Quote:
Originally Posted by dsmith
Hi Finland. Welcome to GIDForums.

What exactly do you mean by tabular format? Do you want your data seperated by tabs? Can you show a sample of what you want the text file to look like? From what I read you want something like 20 lines consisting of:
Code:
city_name temp humidity latitude longitude..... city_name temp ....

Is that correct?
  #4  
Old 08-Jun-2004, 10:06
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by gwk

Is it possible at all to arrange data in tables in .txt files. Or any other alternative for output files?

That is why I asked the question. You can definitely arrange a text file in that format. But I wasn't sure if you wanted something that you could import into excel or something like that. If you truly want a text file that you can print and look to be in tabular format, the fprintf command can be made to align data quite nicely with the format tags and the width specifier.

For example:
CPP / C++ / C Code:
fprintf(outfile,"%-20s%-10s%-10s\n","City Name","Temparature","Humidity");
fprintf(outfile,"%-20s%-10d%-10d\n",city.name,city.temp,city.humidity);
Will give a left padded alignment to the values.

So if this is what you want to do, I would read in all the entries into a custom structure, then close that file and re-output that structure in your tabular format.

HTH,
d
  #5  
Old 08-Jun-2004, 10:45
gwk gwk is offline
Awaiting Email Confirmation
 
Join Date: Jun 2004
Posts: 8
gwk is on a distinguished road

Conversion from a data from line into a tabular form in C/C++


Thanks again dsmith!
Actually the output file is suppose to be input file to a prorgram that takes date in columns and rows form. I think that the solution of padding won't work for it. What do u think?

(I will try to feed the output file once I get output from the proposed solution)
Do you know how to export data to Excel? which could be one possible tabular form.

Is it possible to read file name with C. Later on using pointer and fopen that file is opened and then data is arranged/exported to a newly created file. The newly created file name is suppose to be similar to the original file name.
The idea is that at the end of day I'll convert all files of a directory into a tabular form. I'll have situation where I will know only the name of the directory but not the individual files' names. Invdividual files would be read and converted and saved to correspoing out put files. Let say a directory has 3 files: sample1.txt; sample2.txt; and sample3.txt. These files names are not know beforehand. Only directory name is known. The goal is to creat corresponding output files named sample1out.txt, sample2out.txt, and sample3out.txt. OR sample1out.xls, sample2out.xls, and sample3out.xls.

May I have your email address.
Thanks alot again.
GWK
Finland
  #6  
Old 08-Jun-2004, 11:25
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by gwk
Thanks again dsmith!
Actually the output file is suppose to be input file to a prorgram that takes date in columns and rows form. I think that the solution of padding won't work for it. What do u think?

I see. Do you have any guidelines for what the output format should be? Padding may still work perfectly, if this requires an old column position type where the program is going to look in column 0 for the city name and column 20 for the temparature, etc. This should be your first priority to see exactly what kind of format this needs to be in.

Quote:
(I will try to feed the output file once I get output from the proposed solution)
Do you know how to export data to Excel? which could be one possible tabular form.
Excel has a very powerful import/export feature which can read all types of text files, etc. I often use it to read csv files (comma seperated value) and it imports these files and seperates them into columns automatically.

Quote:
Is it possible to read file name with C. Later on using pointer and fopen that file is opened and then data is arranged/exported to a newly created file. The newly created file name is suppose to be similar to the original file name.
The idea is that at the end of day I'll convert all files of a directory into a tabular form. I'll have situation where I will know only the name of the directory but not the individual files' names. Invdividual files would be read and converted and saved to correspoing out put files. Let say a directory has 3 files: sample1.txt; sample2.txt; and sample3.txt. These files names are not know beforehand. Only directory name is known. The goal is to creat corresponding output files named sample1out.txt, sample2out.txt, and sample3out.txt. OR sample1out.xls, sample2out.xls, and sample3out.xls.
Yes. If this is to be an automatic thing, then excel is probably not the way to go. This should be fairly straight forward to do in C, but the first thing that you need to find out is the format that the file needs to be put in. What program are you trying to import this with?

Quote:
May I have your email address.
Thanks alot again.
GWK
Finland
I hate to be a jerk, but unfortunately no. A couple of reasons. I don't want my e-mail posted publicly in this (or any other) forum and someone in the future may want to do something similar to what you are doing so it would be nice to keep this topic open publically. Does that make sense?

You should be getting close to getting Private Messaging privileges here and then you can send me a Private Message. Then if there is a reason for it, I will gladly give you my e-mail address.

Cheers,
d
  #7  
Old 10-Jun-2004, 04:02
gwk gwk is offline
Awaiting Email Confirmation
 
Join Date: Jun 2004
Posts: 8
gwk is on a distinguished road
Hi dsmith,
Thanks alot for your indepth discussion with me.
The prorgram in which i m going to import is limited to our lab only. No body knows about it. I am new to that program as well. I just checked that it needs log files. I will get sample log files and analyze it then i will let u know.
I will come to this matter soon.
But I got another problem all of sudden. I am use Visual studio .NET. When I debug my code I am getting the following message:
'June10.exe': Loaded 'C:\USERS\Visual Studio Projects\June10\Debug\June10.exe', Symbols loaded.
'June10.exe': Loaded 'C:\WINNT\system32\NTDLL.DLL', Cannot find or open a required DBG file.
'June10.exe': Loaded 'C:\WINNT\system32\KERNEL32.DLL', Cannot find or open a required DBG file.
The program '[2388] June10.exe: Native' has exited with code 0 (0x0).
-----------------
What can I do in this matter.

Regards,
GWK
Finland
  #8  
Old 10-Jun-2004, 06:00
eXiLe eXiLe is offline
New Member
 
Join Date: Jun 2004
Posts: 10
eXiLe is on a distinguished road
You shouldn't warry about this gwk. This is just a log, that show you which modules you can debug. If the debuger can't load the symbols you just can't debug this modules, but that won't reflect your program. The only problem might be if you wanna debug it. You should find a way to load properly this symbols.
  #9  
Old 14-Aug-2007, 17:13
damy damy is offline
New Member
 
Join Date: Aug 2007
Location: Romania,Timisoara
Posts: 26
damy is an unknown quantity at this point

Re: Conversion from a data from line into a tabular form in C/C++


Quote:
Originally Posted by gwk
Do you know how to export data to Excel?

I have the same problem.
Lets say that I have a strcture of students with two fields, name and mark given from the keyboard.
I vant to export this informations in a excel table file and to be able to reuse this file as imput for a similar program.
I did it with binary files with fwrite and fread functions,but I want those informations in a excel table.Is it posible?And I want that badly

Can anyone give me a clue?I have no ideea and I need this information

10x.
  #10  
Old 14-Aug-2007, 17:51
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 574
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: Conversion from a data from line into a tabular form in C/C++


I gotta go right now, but there was a thread on this a month or so ago. Search this forum a bit on 'excel'.
Excel will take most any delimiter: comma , space, tab ... whatever. There is probably a default to use otherwise you will have to tell Excel what the delimiter is. Pick a delimiter which the file won't otherwise be having in in and generate your file like that.
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
burning problems PLEASE PLEASE HELP kelticeire Computer Hardware Forum 4 01-Dec-2006 16:39
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.