GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-May-2005, 16:10
vaha vaha is offline
New Member
 
Join Date: May 2005
Posts: 8
vaha is on a distinguished road

String problem


Hi all,
it's my first string using program. I have problem with do {} while.
CPP / C++ / C Code:

#define MAX_SIZE 30
.
.
.
 do
    { 
       printf(" Enter String::: ");
       gets(str);
    }

 while (strlen(str)<MAX_SIZE);

this is wrong protection? HElp.

2. problem
CPP / C++ / C Code:
char answer;
void main()
{
 ...
do 
  {
     clrscr();
     printf(" Enter String::: ");
     gets( str ); // same problem when i use scanf("%s",str)
     some_function( str );
     printf(" Result:: %s ", str );

   printf("\n\n\n\t\t\t Do you want to continue (y/n)");
   flushall();
   scanf(" %c ", &answer);
   } 
    
   while (answer == 'y' || answer=='Y');
}

problem: when i pres Y/y printf(" enter string") is skiped.and program is finished.
  #2  
Old 24-May-2005, 16:47
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
Don't use gets(str) or scanf("%s", str), use fgets and learn how to handle the trailing newline that may be left over.
  #3  
Old 24-May-2005, 18:11
vaha vaha is offline
New Member
 
Join Date: May 2005
Posts: 8
vaha is on a distinguished road
Quote:
Originally Posted by Dave Sinkula
Don't use gets(str) or scanf("%s", str), use fgets and learn how to handle the trailing newline that may be left over.

that didn't helpd me.
  #4  
Old 24-May-2005, 18:21
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
Long version.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a .html file, check that file for links salemite C Programming Language 10 17-Jan-2008 07:56
Converting string to float CT++ C++ Forum 2 10-May-2005 11:29
inheritance problem ap6118 C++ Forum 8 11-Apr-2005 11:24
Problem to acess to a dynamic string collinm C Programming Language 1 25-Mar-2005 09:21
Problem with string and serial port collinm C Programming Language 13 25-Mar-2005 07:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:47.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.