passing strings
-
My comments to your code: Why do you get 3 char-arrays as parameters, but never use them? Instead you are putting your read data into local variables (which will get destroyed upon leaving the function). You definitely want more error checking when opening the file and reading the data.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
Hi all! i need help.. i m calling fileRead function which reads the file and put some values in three strings cName1 ,cSvnPath1 ,cPassword1...now my question is ...that how should i call this function in main file so that these three strings can be utilised in main file only...??? please answer as early as possible. void FileOperation::fileRead(char cName[100] , char cSvnPath[100] , char cPass[100]) { char cName1[100]; char cSvnPath1[100]; char cPassword1[100]; FILE *fp; fp = fopen("config.txt","r"); fgets(cName1 , 100, fp); fgets(cSvnPath1 ,100 , fp); fgets(cPassword1 ,1 ,fp); fclose(fp); }
void FileOperation::fileRead(char cName[100] , char cSvnPath[100] , char cPass[100]) { //char cName1[100]; //char cSvnPath1[100]; //char cPassword1[100]; FILE *fp; fp = fopen("config.txt","r"); fgets(cName , 100, fp); fgets(cSvnPath ,100 , fp); fgets(cPass ,100 ,fp); fclose(fp); } Now use the arguments in your main file
-
these mistakes r becoz i was trying something to get solution but i did nt get..i want these local variables to be passed to main function
dona jain wrote:
i want these local variables to be passed to main function
Why? Wouldn't it be better to pass the buffers from Main to your function? Local variables get destroyed on leaving their scope.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
void FileOperation::fileRead(char cName[100] , char cSvnPath[100] , char cPass[100]) { //char cName1[100]; //char cSvnPath1[100]; //char cPassword1[100]; FILE *fp; fp = fopen("config.txt","r"); fgets(cName , 100, fp); fgets(cSvnPath ,100 , fp); fgets(cPass ,100 ,fp); fclose(fp); } Now use the arguments in your main file
-
dona jain wrote:
i want these local variables to be passed to main function
Why? Wouldn't it be better to pass the buffers from Main to your function? Local variables get destroyed on leaving their scope.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
ohh..thanx...can u tell me how to call this function in main FileOpration fcRead; fcRead.fileRead(); this or something else?? fileRead() -->:^) is this correct?
You just pass the arguments you want to your function. Calling a function and passing parameters is basics C++ so I really suggest you read some book before going on with classes otherwise you'll get totally lost.
Cédric Moonen Software developer
Charting control [v1.2] -
ohh..thanx...can u tell me how to call this function in main FileOpration fcRead; fcRead.fileRead(); this or something else?? fileRead() -->:^) is this correct?
char cName[100]; char cSvnPath[100]; char cPass[100]; fileRead(cName, cSvnPath, cPass);
-
ohh..thanx...can u tell me how to call this function in main FileOpration fcRead; fcRead.fileRead(); this or something else?? fileRead() -->:^) is this correct?
dona jain wrote:
can u tell me how to call this function in main
oh my god !!! :omg: you know what ? stop this immediately, go to a book shop, find Kernigan & Ritchie's Book about the C language, and read (i mean, read and LEARN) !!! then you'll find all this becoming very easy
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Ranjoy Guha already programmed you a function which you simply need to give the buffers as parameters:
char buffer1[100];
char buffer2[100];
char buffer3[100];FileOpration fcRead;
fcRead.fileRead( buffer1, buffer2, buffer3);Now look at buffer1, 2, 3 in the debugger. As a side-question: Do you really desire to learn C? And why do you ask your questions in a C++/MFC-Forum? The C++ way of reading a file would be
std::ifstream
.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
char cName[100]; char cSvnPath[100]; char cPass[100]; fileRead(cName, cSvnPath, cPass);
-
Hey..its working now...u r realy a nice person here ..others always uggest book..never answer me properly. Thank A lot:-D
-
Hey..its working now...u r realy a nice person here ..others always uggest book..never answer me properly. Thank A lot:-D
hey, it's not to annoy you if we suggest you to read books... it's for your own efficiency dude ! it's as if you drive a car without a license... how can you drive on a highway then if you don't learn driving first ? :doh: oh and By the way, if we "never answered properly" as you say, it's because you never ask properly ! :suss: and at last, "u", "y" and "r" are letters; "you", "why" and "are" are the words to use if you want anybody to understand you. you're not an a chat room, and people around here are from all over the world. be compliant with the policies, and everything will be fine. if you don't want to comply, i'll stick on your ass to warn you as you already started to know me for this ;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Ranjoy Guha already programmed you a function which you simply need to give the buffers as parameters:
char buffer1[100];
char buffer2[100];
char buffer3[100];FileOpration fcRead;
fcRead.fileRead( buffer1, buffer2, buffer3);Now look at buffer1, 2, 3 in the debugger. As a side-question: Do you really desire to learn C? And why do you ask your questions in a C++/MFC-Forum? The C++ way of reading a file would be
std::ifstream
.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening wordsjhwurmbach wrote:
And why do you ask your questions in a C++/MFC-Forum?
man, don't be rude on this... there's no C board, and most C++ programmer can understand a C problem. but the problem of the OP is that he doesn't know anything (maybe VB...) but he doesn't want to learn either :doh:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
hey, it's not to annoy you if we suggest you to read books... it's for your own efficiency dude ! it's as if you drive a car without a license... how can you drive on a highway then if you don't learn driving first ? :doh: oh and By the way, if we "never answered properly" as you say, it's because you never ask properly ! :suss: and at last, "u", "y" and "r" are letters; "you", "why" and "are" are the words to use if you want anybody to understand you. you're not an a chat room, and people around here are from all over the world. be compliant with the policies, and everything will be fine. if you don't want to comply, i'll stick on your ass to warn you as you already started to know me for this ;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hey..its working now...u r realy a nice person here ..others always uggest book..never answer me properly. Thank A lot:-D
Dont Mind... But as Sunit and Tox says you must read some c++ books for your further knowledge.
-
I think Mr Ranjoy Guha is not the inventor of C++ .Without reading those books even he could not have answered ur problem::laugh:
never say die
-
well i knew this very well that without reading books..i can't...but if its some sort of urgency.. you hav to take someone's help ...is that wrong?...please forget all those past mistakes...and lets be friends.;)
dona jain wrote:
well i knew this very well that without reading books
well, don't get me wrong. i'm not paid to answer on this board. all i do is because i want to and i love it. but i'm still thinking you have some lack of knowledge that you should fix fastly. calling a finction is part of the basics of the C/C++ (and any programming - in general...) languages. if you can't figure out how to call one, then you should start from the beginning.
dona jain wrote:
but if its some sort of urgency
i'm not a doctor ;P
dona jain wrote:
you hav to take someone's help
i'm not obliged to do so, and know that i do my best anyway. but sometimes, i really don't understand the question, so how to help then ? and if i was obliged to help, then the one who's asking should be obliged to ask with all the useful informations we must have to answer well in a one step. Is that Wrong ?
dona jain wrote:
please forget all those past mistakes
i hope you understood me and will make efforts in the future. for my part, i have nothing against you. just against your questions ;) Sincerely... :rose:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
- i don't understand your question 2) i don't understand your code either 3) no need to say "i need help" (if you ask something, it's obviously because you need help), nor "please answer as early as possible" (people do reply when then know the answer... if no one reply you, it's because no one knows, or no one got your question). so, i ask you the question. What is it you're trying to achieve, and what have you already tried ? what do you mean by "these three strings can be utilised in main file only" ??
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
if you ask something, it's obviously because you need help
Simple, yet powerful. :)
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hi all! i need help.. i m calling fileRead function which reads the file and put some values in three strings cName1 ,cSvnPath1 ,cPassword1...now my question is ...that how should i call this function in main file so that these three strings can be utilised in main file only...??? please answer as early as possible. void FileOperation::fileRead(char cName[100] , char cSvnPath[100] , char cPass[100]) { char cName1[100]; char cSvnPath1[100]; char cPassword1[100]; FILE *fp; fp = fopen("config.txt","r"); fgets(cName1 , 100, fp); fgets(cSvnPath1 ,100 , fp); fgets(cPassword1 ,1 ,fp); fclose(fp); }
Since you're obviously using C++ you should use it correctly. Don't pass crap like char cName[100] as arguments in functions or as variables. Use the STL's std::string class for representing a string. Thus you would rewrite the above as void FileOperation::fileRead( const std::string& cName, const std::string& cSvnPath, const std::string& cPass ) second problem - you have variables defined within the local scope of your function with the same name as the arguments you've defined in your function. That could be problematic. You should go out and get a good book on C++ first and get comfortable with the basics.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog