LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2016, 03:28 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,789

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304

have you tried what I posted already? http://www.linuxquestions.org/questi...67/#post810033
 
Old 02-25-2016, 03:35 AM   #17
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP: Quote your complete program. Clearly describe the problem/error you experience. Then we can help you.
 
Old 02-25-2016, 11:11 PM   #18
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by hardikgohil1988 View Post
Sorry mistaken code posted

Code:
char c[10];

printf("Enter Your Choice :");
scanf("%s",c);
i = atoi(c);
switch(i){
}
example I type

Enter your choice:123backspace

should be 12 but prints invalid option as defined at default switch case.
My test code:
Code:
$ cat readNum.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
    int i;
    char c[10];

    printf("Enter Your Choice :");
    scanf("%s",c);
    i = atoi(c);
    printf("You entered %d\n",i);
}
$ gcc -o readNum readNum.c
$ ./readNum 
Enter Your Choice :784       // entered 789<backspace>4
You entered 784             
$ ./readNum 
Enter Your Choice :12        // entered 123<backspace>
You entered 12               
$ _
Clearly, you deviated from the script somewhere.

Last edited by psionl0; 02-27-2016 at 10:28 PM.
 
Old 02-29-2016, 03:15 AM   #19
hardikgohil1988
Member
 
Registered: Sep 2014
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thank you all.

problem was with putty terminal setting

http://the.earth.li/~sgtatham/putty/...onfig-keyboard

this post helped me
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
backspace problem with scanf hardikgohil1988 Linux - Embedded & Single-board computer 2 02-22-2016 09:05 AM
[SOLVED] scanf problem sree_ec Programming 10 05-13-2011 10:12 AM
problem with scanf fssengg Programming 3 03-29-2005 04:27 AM
scanf() problem. LUB997 Programming 3 12-19-2004 08:03 PM
backspace problem moschi Linux - Newbie 4 03-23-2004 05:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration