Re: scanf - compiles but causes error Programming Software Development by diablo scanf("%d",r); The above statement is wrong logically. The correct statement would be scanf("%d",&r); You would be storing the value entered by the user at the address of r. So you have to use &r. So modify the other scanf statements. :) Re: Scanf problems Programming Software Development by jephthah scanf is a notoriously difficult function to use, especially for beginners. … Re: scanf error in c Programming Software Development by deceptikon > scanf("%"PRIu16, &y); The PRI\* macros are for printf. Use the SCN\* macros for scanf, they're not interchangeable: scanf("%"SCNu16, &y); Re: scanf() to read in a string... Programming Software Development by jared_masc scanf is the only part i'm supposed to use unfortunately... Re: scanf problem Programming Software Development by Ancient Dragon … key '\n' in the keyboard buffer, so the next time scanf() is called it will only see '\n'. One solution is… to replace scanf() with fgets() which will remove '\n' if there is room… Re: Scanf and errors Programming Software Development by Ancient Dragon scanf() expects the argument to be a pointer, and you passed just a float. Add the & to make num1 a pointer, like this: [icode]scanf("%f", &num1);[/icode] scanf help Programming Software Development by sourabhyogi … the first Y line. Can I avoid that? I use scanf to read the first character and then it is true… I used scanf in a while loop to read the rest of the… Re: scanf help Programming Software Development by Schol-R-LEA I would, first off, recommend against using `scanf()` directly for this; since the input is by line, and … Re: scanf help Programming Software Development by sourabhyogi Thanks Schol-R-LEA. I am new to C. I have only been taught scanf and getchar. scanf discussion Programming Software Development by Ptolemy … loop little more than a kludgy hack. [QUOTE]scanf() and gets() have the exact same problem with … well. :) [QUOTE]It is therefore necessary after every scanf() call that reads non-character data (ints, floats, etc…-whitespace character entered, effectively clearing the buffer from previous scanf() calls.[/quote] Why the loop? What if "… Re: scanf discussion Programming Software Development by WaltP … way. [/quote]My point exactly. [INLINECODE]scanf()[/INLINECODE] is dangerous and inadequate reading strings (…]. Yes, formatted input is necessary, but [INLINECODE]scanf()[/INLINECODE] has too many problems. [INLINECODE]sscanf()[/INLINECODE…formatted user input". [/quote] But [INLINECODE]scanf()[/INLINECODE] is meant for [I]user input[/I… Re: scanf discussion Programming Software Development by WaltP … have no idea how to clear the buffer using scanf() while reading a number. Especially with ill-formatted input…=Ptolemy;456262]C doesn't recognize meatware or keyboards. scanf is meant for formatted input from stdin. It happens …user interaction. Unfortunately, it does need to interact, and scanf() has been the function of choice. I still say… Re: scanf discussion Programming Software Development by Ptolemy … what a student programmer generally knows, how is using scanf() to read an int and leaving the return in … instructors have no idea how to clear the buffer using scanf() while reading a number. Especially with ill-formatted input … every time. It looks like you want me to ignore scanf, sscanf, strto*, ato*, and any other existing parsing mechanism… Re: scanf discussion Programming Software Development by Aia …you figure out yet why you should avoid using scanf? [/URL] To which Ptolemy responded: >… "Enter an integer: ", stdout ); fflush( stdout ); while( scanf( "%d%c", &i, &c ) != 2…getchar(); return 0; } [/code][quote]Ptolomy wrote: >while( scanf( "%d%c", &i, &c ) != … Re: scanf discussion Programming Software Development by WaltP …every time. It looks like you want me to ignore scanf, sscanf, strto*, ato*, and any other existing parsing… problems. You simply can't validate input with [INLINECODE]scanf()[/INLINECODE]. But you [I]can[/I] with [INLINECODE]…B]is[/B] user input, because that is what [INLINECODE]scanf()[/INLINECODE] is used for 99% of the time. :icon_rolleyes:… Re: scanf discussion Programming Software Development by Ptolemy … were the one who wrote those articles. :) [QUOTE]scanf() is dangerous and inadequate reading strings (only reads to …everybody. -- Bill Cosby That's how I feel about scanf().[/QUOTE] [QUOTE]No, but it solves most of them…keyboard![/QUOTE] C doesn't recognize meatware or keyboards. scanf is meant for formatted input from stdin. It happens… Re: scanf discussion Programming Software Development by Dave Sinkula [QUOTE=Ptolemy;456139]Despite what the regulars here say, switching from scanf to fgets/sscanf isn't going to solve all of your problems with scanf.[/QUOTE]Nope. But it easily passes the 80/20 rule for acolytes. Scanf Infinite loop Programming Software Development by Soileau …++){ printf("Enter the value in position %d: ",i); scanf("%f",&vector1.data[i]); fflush(stdin); } printf…++){ printf("Enter the value in position %d: ",i); scanf("%f",&vector2.data[i]); fflush(stdin); } printf… Re: Scanf experiments, please give explanations Programming Software Development by deceptikon …type "gabcxyz" the output will be: scanf() returned 1 scanf() extracted 'g' Next character: 'x' If …type "gxyz" the output will be: scanf() returned 1 scanf() extracted 'g' Next character: 'x' These…"gabc123z" the output will be: scanf() returned 2 scanf() extracted 'g' scanf() extracted '123' Next character: 'z' … Re: Scanf vs fgets Programming Software Development by Narue …5000 characters, and as long as there's no whitespace scanf will read 5000 characters. The big question is, where … is a good choice for that. So this: [code] scanf("%d",&element->data); [/code] becomes this…the much better strtol, and your own conversion routine. Using scanf for reading anything but string data is actually not that… Re: Scanf Infinite loop Programming Software Development by Soileau … a little rude. I didn't mean to imply that scanf was superior to fgets or getchar. I just haven't…, and I have been taught to use scanf. I am simply more comfortable using scanf, because I have never extensively used getchar…. Perhaps if you could provide reasoning behind your discrimination of scanf, I could learn more about it myself and make a… Re: Scanf Infinite loop Programming Software Development by Dave Sinkula …Get over it and use functions that actually work.[/B] scanf works just fine. The problem is ignorant programmers who don…'t understand the rationale behind it. Calling scanf crappy after trying to read interactive input is much like…;http://bytes.com/topic/c/answers/215517-warning-against-scanf#post840862"]this related item[/URL] today. Re: Scanf Infinite loop Programming Software Development by Ancient Dragon … I input a character instead of an integer during a scanf("%d"....);[/b] That's why I always (or… normally) use fgets() instead of scanf(), then after validating input convert the text to an int… Re: Scanf Infinite loop Programming Software Development by Soileau Everybody says that. I do not understand why jump statements are so frowned upon. Anywho, I would prefer to use scanf over getchar. Any ideas? Re: Scanf Infinite loop Programming Software Development by Ancient Dragon … and understand. >>Anywho, I would prefer to use scanf over getchar. I didn't say [b]getchar()[/b]. I…'t matter whether you or I like it or not -- scanf() is a crappy function that does crappy things to the… Re: Scanf Infinite loop Programming Software Development by WaltP …: [url=http://www.gidnetwork.com/b-59.html]Why [ICODE]scanf()[/ICODE] is bad[/url] If you haven't been taught… anything but [ICODE]scanf()[/ICODE], you must live with its idiosyncrasies until you are… Re: Scanf Infinite loop Programming Software Development by Ancient Dragon …' in the keyboard buffer, as you have already found out, scanf() has a huge security issue as shown in the link… I just gave you. scanf() will let you enter as many characters as you like… Re: Scanf Infinite loop Programming Software Development by Narue [B]>scanf() is a crappy function that does crappy things to >…. Get over it and use functions that actually work.[/B] scanf works just fine. The problem is ignorant programmers who don…'t understand the rationale behind it. Calling scanf crappy after trying to read interactive input is much like… Re: Scanf Infinite loop Programming Software Development by jephthah … work" parade. (4) the state of being crappy. (5) scanf() . scanf() and fgets() problems. Programming Software Development by coril … is too long, enter new name: "); scanf("%[^\t\n]", &na); }// end… na check printf("\nEnter priority: "); scanf("%d", &pr); while (pr>…priority, enter new priority (0-100): "); scanf("%d", &pr); }//end pr …