Click here to Skip to main content
15,897,226 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Writing a huge structure data to file Pin
leon de boer6-Jan-18 4:11
leon de boer6-Jan-18 4:11 
QuestionHow to return a string from a user defined function to main function ? Pin
Tarun Jha3-Jan-18 3:21
Tarun Jha3-Jan-18 3:21 
AnswerRe: How to return a string from a user defined function to main function ? Pin
David Crow3-Jan-18 6:24
David Crow3-Jan-18 6:24 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha3-Jan-18 7:20
Tarun Jha3-Jan-18 7:20 
GeneralRe: How to return a string from a user defined function to main function ? Pin
David Crow3-Jan-18 7:29
David Crow3-Jan-18 7:29 
AnswerRe: How to return a string from a user defined function to main function ? Pin
Jochen Arndt3-Jan-18 12:48
professionalJochen Arndt3-Jan-18 12:48 
AnswerRe: How to return a string from a user defined function to main function ? Pin
Member 115604903-Jan-18 14:48
Member 115604903-Jan-18 14:48 
AnswerRe: How to return a string from a user defined function to main function ? Pin
leon de boer3-Jan-18 15:07
leon de boer3-Jan-18 15:07 
As per your last post lets fix my code from it into a function .. which is what I assume you are trying to do
C
int StringInput (char* name, int namemax)
{ 
   int c;
   int namelen = 0;  // initialize array position index to zero
   if (name && namemax > 1) {  // Lets be safe and check pointer valid and space > 1
      do {
         c = getc(stdin);  // fetch the integer keyboard read value .. EOF safe
         name[namelen++] = (char) c;  // convert the integer to a char and place in array .. increment position
      } while (c !=EOF && c != '\n' && namelen < namemax-1);  // repeat until EOF or new line or hit max length-1 (need space for '\0')
      temp.name[namelen-1] = '\0';  // Make C null terminated string (overwrite last EOF or '\n')
   }
   return(namelen); // return the name length
}

/** HOW to USE *//
int main(void)
{
   char name[100];
   int len = StringInput(&name[0], sizeof(name));
   // OR if you don't need length just
   StringInput(&name[0], sizeof(name));
}

Now if this is for uni or commercial then you probably want this form ... An excercise for you is to understand why and how to do it
C
int StringInput (const char* name, const int namemax, const FILE* source)

In vino veritas


modified 3-Jan-18 21:27pm.

GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha3-Jan-18 19:29
Tarun Jha3-Jan-18 19:29 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Victor Nijegorodov3-Jan-18 23:04
Victor Nijegorodov3-Jan-18 23:04 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha4-Jan-18 4:02
Tarun Jha4-Jan-18 4:02 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Richard MacCutchan3-Jan-18 23:21
mveRichard MacCutchan3-Jan-18 23:21 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha4-Jan-18 4:05
Tarun Jha4-Jan-18 4:05 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Richard MacCutchan4-Jan-18 4:10
mveRichard MacCutchan4-Jan-18 4:10 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha5-Jan-18 0:48
Tarun Jha5-Jan-18 0:48 
GeneralRe: How to return a string from a user defined function to main function ? Pin
leon de boer4-Jan-18 14:32
leon de boer4-Jan-18 14:32 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha5-Jan-18 0:46
Tarun Jha5-Jan-18 0:46 
QuestionTo make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha2-Jan-18 2:35
Tarun Jha2-Jan-18 2:35 
AnswerRe: To make a function in C which does not except "\n" & EOF as input. Pin
David Crow2-Jan-18 3:05
David Crow2-Jan-18 3:05 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha3-Jan-18 3:48
Tarun Jha3-Jan-18 3:48 
AnswerRe: To make a function in C which does not except "\n" & EOF as input. Pin
Richard MacCutchan2-Jan-18 3:36
mveRichard MacCutchan2-Jan-18 3:36 
AnswerRe: To make a function in C which does not except "\n" & EOF as input. Pin
leon de boer2-Jan-18 13:38
leon de boer2-Jan-18 13:38 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha3-Jan-18 3:40
Tarun Jha3-Jan-18 3:40 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
David Crow3-Jan-18 3:57
David Crow3-Jan-18 3:57 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha3-Jan-18 4:59
Tarun Jha3-Jan-18 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.