C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 5th, 2006, 12:44 AM
shady_2038 shady_2038 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 2 shady_2038 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 34 m 25 sec
Reputation Power: 0
Read a string from a file and execute a function

Hi,

I have a general programming question. If I have an external file in C and in my main program, I simply want to read data from the file, how do I do it so that the string it reads from a line in the file, in the main program I want to execute its fucntion. Example, string read from file is "ICP_IP" and in main I want to execute that particular function which is defined in the main. This will have to be done in my while loop in main which will stop when it hits eof.

Is it a better idea to simply read the data and save it all in a structure and then do it or do each one dynamically like now?

thanks any hep would be GREATLY appreciated

Reply With Quote
  #2  
Old March 9th, 2006, 10:00 PM
lostlander lostlander is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 3 lostlander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m
Reputation Power: 0
Send a message via MSN to lostlander
do u mean this?
=>
int main()
{
FILE *fp;
fp=fopen("input.txt","r");
char s[256];
while( fgets(s, sizeof(s),fp)!=NULL)
{
cout<<s<<endl;
//func(s); //call the function to manipulate this line
}
fclose(fp);
return 0;
}

Reply With Quote
  #3  
Old March 10th, 2006, 02:50 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
hm.. try this

struct string
{
string name
};
ifsteam inFile;
string filename;


char buffer[40];

InFile.open(filename.c_str());
if(!inFile)
{
cout<<"cannot read file"<<endl;
return 1;
}

int track=0;
while(track<#ofnames && !inFile.eof())
{
inFile.get(buffer,40);
string.name=buffer;

}
there might be a few errors but i think i put the general idea into there

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Read a string from a file and execute a function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT