Tuesday, July 14, 2009

C File I/O question.?

okay.. I've learned to take the content of a file and output it with printf... now I need someone to explain to me how i would set each line into a global variable. As sort of a configuration file.





like this.








file - bot.conf





BotNick "nicknamehere"


BotUser "botuserhere"





and it would set those into a variable to be used by the entire programme.





Also, if it's not too difficult, i'd like to have support for shell style comments.

C File I/O question.?
Declare the global variables *before* any of your routines, so their scope is the entire source file:





#include ...





char globNick[256];


char globUser[256];





...





int grabGlobal() {


/* In here, you assign to the global variables. */


}





int main () {


}





If your global variables get used in any other files, you declare them similarly at the top of the file:





extern char nickGlob[256];





Shell-style comments depend on your shell: look up the comment syntax. For most UNIX-based shells, it's simply "# " (sharp - space) at the start of the line.





Does that help?

innia

No comments:

Post a Comment