C :: Using Scanf To Read A Character From Standard Input
Nov 1, 2013
So running the following code
Code:
#include <stdio.h>
int main(void) {
char c;
int i=1;
while (scanf("%c", &c)==1)
printf("loop sequence %i: %c(%i)
[Code] ......
Done it seems a "carriage return" serves two purposes here, one is to signal the program to read in the character typed in before the "carriage return", another serves as a second character typed, how can i do this cleanly, that is without having to use a "carriage return" as the second character to signal "I've typed in the first character already".
View 2 Replies
Oct 30, 2013
so i'm using scanf() this way
Code:
int i;
while (scanf("%i", &i))
printf("%i ", i);
printf("
done
");
i tried several combination of Ctrl+D and "Enter", it's not terminating, Ctrl+C just "cancels" the whole thing without printing "done", i'm running this on linux installed on a PC
View 9 Replies
View Related
Mar 11, 2012
Below given is the code, which allocates memory for a structure dynamically and stores value in its member. The problem is in the last scanf statement which reads 'ch'. The code will be in infinite loop as it doesnt executes the last scanf statement. The solution for this is (i use this) to add one more similar scanf statement for 'ch' in the very next line. If i do so, it executes the statement, reads 'ch' and then continues.
I want to know why it behaves like that..
struct student{
int usn;
};
int main(){
char ch;
struct student *s;
s=(struct student *)malloc(sizeof(struct student));
[Code] ....
View 11 Replies
View Related
Mar 21, 2013
Here's my code, it's for a poker hand evaluator
input:
'ad 2d 3d 4d 5d...
...4s 5s 6s 7s 8s'
I think it should go through all the 10 crads and disply the name of each card, but it seems to only do it for the second hand
Code:
include <stdio.h>
#include <ctype.h>
int main( void ) {
char inputtedhand[64];
int z=0, counter=0;
int index;
int i=0,m=0,n=0;
[Code].....
View 3 Replies
View Related
Aug 10, 2012
How do I write an a program that will read an input file character by character?
View 1 Replies
View Related
Feb 19, 2014
Write code to do the following:
1) declare a variable ptr as a pointer to int and initialize it to NULL
2) dynamically allocate memory for an array of 100 elements
3) read 100 elements from the standard input device and store them in the array.
This is what I have so far, I'd like to know if its ok or if something is wrong.
int *ptr = NULL;
ptr = new int[100];
cin >> dataPtr [arr];
View 2 Replies
View Related
Apr 13, 2014
A Bookseller makes special discount for multiple orders of a book as follows:
AMOUNT and DISCOUNT as follows.
5-9 5% 10-14 10% 15-19 15% 20+ 20%
Write a C main function to read the amount of order from the standard input and compute and print the total price of the given order after the discount. Assume that unit price of a book is 10.00$
My problem is that.When i start with this
Code:
#include<stdio.h>
#include <stdlib.h>
int main(void)
{
int number;
float TotalPrice;
printf("enter a number:");
[Code] ....
I get 0 if i enter a number between 0 and 4(0 and 4 included). I don't know where I am doing a mistake. I also want to know if i can handle this buy just if statements. or how can i do it by while and for loops ?
View 1 Replies
View Related
Jan 12, 2015
I'm very new to c programming and I have some background in C# and java. I am supposed to read a string from input then determine in that string, which character is the largest, i.e. I think b>e and e>z, e.t.c. If the string is empty I should return '