passing strings
-
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); }
-
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); }
- 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]
-
- 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]
I simply mean that i m calling fileRead() in main()..i have other three strings ...a[] ,b[],c[]...now i want that data from cName1 ,cSvnPath1 and cPassword1 should get passed in main to Strings a, b, c respectively..i hope u'll get it now..So, how can it be done..i m getting problem in initialising...thanks.:-O
-
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); }
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 -
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?
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]
-
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] -
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