Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exiting a function

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
How would i go about exiting this function with an input 'X' from the keyboard when the name is read in.

any help would be greatly appreciated....thanks :))

Code:
    int i;
    for(i=0;i<=9;i++,*ptr++)
    {
    printf(&quot;\n\tName    :    &quot;);
    scanf(&quot;%s&quot;,&ptr->name);
    printf(&quot;\n\tID    :    &quot;);
    scanf(&quot;%d&quot;, &ptr->identity);
    }
 
You might use a temporary variable to hold the input name, and if it's &quot;X&quot;, break out of the for loop. If it's not, assign your temp variable to the permanent location, then proceed with your input. BTW, if this is in C++, why use printf and scanf, when cin and cout are much more civil?
 
I tried using ptr->name but as its a string and not a char it won`t allow me to perfom the if (ptr->name=='x') etc

i`m using C for this, but the C forum isn`t as good as here for answering C questions for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top