GIDForums  

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

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Feb-2009, 08:19
minwei86 minwei86 is offline
New Member
 
Join Date: Oct 2008
Posts: 13
minwei86 is an unknown quantity at this point

array problem


Hello,

i wan to do c++ program in ubuntu that able to write a summary on the directory example is

drwx-x John 4096
d-w--x John 14
lrwx-x John 2300

How to i use array to put per column into array then access them so i can generate a report so it will be like this

Summary
Total directories = 2 ( the number of d in front determine it)
total link files = 1 ( the number of l in front determine it)
Name of user = John
Total size = 6410 (the total size of last column)

for now is i using char to determine the directories and link file

CPP / C++ / C Code:
int main()
{
char input[100]
int directory = 0;

while(cin>>input)
{
if(input[0] == 'd')
directory++;
}
cout<<dir<<endl;
}

this is what i done to find the directories and link, but i cant use char method to grab name and calculate total size...anyone can tell me any method to generate the report...ty for all help
Last edited by LuciWiz : 09-Feb-2009 at 09:00. Reason: Please insert your C++ between [cpp] & ]/cpp] tags
  #2  
Old 09-Feb-2009, 12:35
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 758
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: array problem


There are several ways to retain the data:
1) You could keep an array of strings, each entry being a line from the file. Then you could have functions that would read the string to tell you information like:
CPP / C++ / C Code:
bool IsDirectory( char* line )
{
// returns true if it is a directory entry, false otherwise
}

2) You could define a structure that represents one of these entries and keep an array of these structures. Then, when you read a line from the file, fill the structure and append it to the array.


On a side note, your report really does not require you to retain any of the data. Each of those fields is a count that can be incremented when parsing a line, just like you did with "directory" in your example.

Also, it looks like one of your questions is about converting a char[] to an integer. See atoi().

I hope this helps. Please post more specific questions if you need more help.
  #3  
Old 09-Feb-2009, 17:35
Newhunter Newhunter is offline
Awaiting Email Confirmation
 
Join Date: Jan 2009
Location: Rio de Janeiro, Brasil
Posts: 11
Newhunter will become famous soon enough

Re: array problem


Be more specific in your questions. Nobody will do the program for you!

Bye!
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

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
Array Problem lief480 C++ Forum 3 26-Oct-2008 09:12
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 15:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 16:16
Loop problem on an array trp_be C Programming Language 1 06-Jan-2007 07:49
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 19:31

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

All times are GMT -6. The time now is 23:05.


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