C :: How To Signal End Of Standard Input Using Scanf

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


ADVERTISEMENT

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 View Related

C :: Getchar - Clear Input Buffer For Next Input Through Scanf

Aug 13, 2014

I would just like to know what does

while( (c =getchar())!='
' && c !=EOF );

do ? and how it do it?

I have see it in a example to clear the input buffer for next input through scanf but does not know its working clearly.

it is used in this example :

Code:
#include<stdio.h>
struct linklist {
char value[20];
struct linklist *next;
};
struct linklist *head,*curr;

[Code] .....

View 4 Replies View Related

C :: Getting Char As Input By Scanf

Mar 31, 2014

In GCC v4.6, I am encountering a strange problem. If I try to get a character input and a int input like this:

Code:

int main()
{
int a;
char b;
scanf("%d",&a);
scanf("%c",&b);
}

the compiled program asks for input only one time. On the other hand, if I do the char scanf earlier like this:

Code:

int main()
{
int a;
char b;
scanf("%c",&b);
scanf("%d",&a);
}

it asks for input twice.

View 6 Replies View Related

C++ :: Input Using Printf / Scanf

Oct 28, 2014

How to store the value in this case.. The topic is called "limited summation".. The following is the guideline for this problem:

Write a program in a folder called "sum" with a source file of main.cpp that does the following:

•prompt a user to enter a maximum number of entries, make the prompt "max # entries"

•prompt a user to enter a threshold sum, make the prompt "threshold"

•using error checking logic, let a user enter base-10 signed numbers until at least one of the following conditions is true:

or the maximum number of entries is reached
or the sum of entered numbers has reached (>=) the threshold

•print the sum of all the entries, just the number and a linefeed at the end of the line

Error checking means entries that are not numbers are detected and ignored. You are to use printf and scanf in this assignment (no cin or cout).

View 3 Replies View Related

C :: Scanf Input By The User Into Function

Apr 19, 2013

I tried to scanf the input by the user into the function but it does not read my input. Read on one of the thread, it said that to scanf a input into a double, need to use %1f instead to %d (which normally used. I tried changing it to %1f and it still did not work.

Code:
#include <stdio.h>
#include <math.h>
/* function main begins program execution */
int main( void )
{
double amount; /* amount on deposit */

[Code] ....

View 2 Replies View Related

C/C++ :: If Statement Comparing Array To Scanf Input

Oct 25, 2014

The issue that I'm having is that when I run this part of the code it seems to enter the if statement and set it to 0 when comparing the array to the input.

What I want it to do is to search the array for the grade, set it to zero, and then exit the loop in case there are any repeat grades. It always sets the first number to 0 and then exits.

//Below is the prototyping for the array

int grades[14] = {60,50,50,20,75,90,0,0,0,0,0,0,0,0};

//There is some code between here, but it is probably not relevant so I didn't post it.

printf("Enter the grade that you want to remove. Press Enter after each input.");
printf("Enter 0 to exit: ");

[Code] ....

I didn't mean to leave the "prototyping" part in the code. I was initially going to put the function prototypes in there, but decided it wasn't necessary for the question.

View 6 Replies View Related

C :: Why Not The First Line At The Standard Input Read

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

C/C++ :: Grep Hanging For Standard Input

Mar 5, 2014

So I'm working on an assignment that is roughly about implementing the grep utility, only it has to be programmed in C. The weird nuance of the assignment is that while we are implementing the utility, we can use grep only we cannot pass grep a filename to search through(we are supposed to pipe a line from the file to standard input so that grep can examine it there.) Anyways, when I reach execlp, it will print out what is in stdin from the terminal, but it hangs at that point and I have to press Ctrl+Z to exit. I probably have the most difficulty with using this function, so I came up with a smaller scale model to get the basics down. Anyways, here's my code:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char* argv[]){

[Code] ....

View 10 Replies View Related

C/C++ :: Writing And Reading From Standard Input

Mar 18, 2015

I have an HTTP/1.0 webserver that I'm building in C that needs to exhibit CGI script functionality. Specifically, what I'm having trouble with is that I have two processes: process 1 is the webserver, process 2 is the CGI script. I fork in the webserver, and then call exec to run the CGI script (specifically, I used execv()). I've read from the CGI specifications in the RFC that in the case of a webserver receiving a POST request, the CGI script should read the arguments for the POST request from stdin. However, when I write to stdin, it simply echoes what was written to the terminal window and when the CGI script tries to read from stdin, it blocks.

So, with all that said, I'm pretty sure there is some simple conceptual explanation to my problem, but I can't figure it out. Do I need to use pipes or some form of interprocess communication to send the data from the webserver to the CGI script, or can it just be done with stdin (and possible stdout)?

View 2 Replies View Related

C :: Check To See If String From Standard Input Is Alphanumeric Or Not?

Dec 25, 2014

I'm trying to check to see if a string from standard input is alphanumeric or not. I feel as though there may be a function for this but...

Code:
for(test_pass = i; test_pass < i; i++){
if(test_pass[i] == ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'))
printf("Your password is alphanumeric!
");
}

The compiler wasn't too happy with this.

View 10 Replies View Related

C :: Accept Password From Standard Input And Goes Through All Possible Combinations Until It Matched

Dec 24, 2014

I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?

View 1 Replies View Related

C++ :: Read 100 Elements From Standard Input Device And Store Them In Array

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

C :: Read Amount Of Order From Standard Input / Compute And Print Total Price After Discount

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

C :: Signal Function Defined Twice With No Error?

Dec 13, 2013

I'm using a library in my code in a file called "my_signal.c". In this file I've defined this function:

Code:
Sigfunc * signal(int signo, Sigfunc *func){
struct sigaction act, oact;
...
}

Since the signal function is also in file signal.h and I included it in "my_sygnal.h" file, I'm wondering why the compiler did not say anything about this "double declaration" of the function with the same name.

View 9 Replies View Related

C++ :: Signal Or Array Or Vector Shifting?

Dec 6, 2013

This can be done very easy, but I assume there is a better way to do it.

assume that I have a vector or a signal like

x=[1 1 1 1 1]

want to shift it by one unit to the right I have

x[n+1] gives

xn=[0 1 1 1 1 1]

and x[n-1] vies

xn=[1 1 1 1 0]

as you can see the length of the original vector or array does not change.

How can I solve this problem without specify the length of the output vector. The size of the output array should be the same as the input array, but I couldn't find a way to do it without adjusting the size.

View 2 Replies View Related

C :: Program Received Signal - Segmentation Fault

Sep 29, 2014

gdb result is

Code:
Program received signal SIGSEGV, Segmentation fault.
isoc99_fscanf (stream=0x0, format=0x4014e0 "%u %u %u %u")
at isoc99_fscanf.c:30
30 isoc99_fscanf.c: No such file or directory. Code:

[Code].....

View 2 Replies View Related

C :: Linux IPC Implement Signal And Slot For New Message

Dec 4, 2014

I'm new in IPC. I would like to implement a signal of a new message, which calls the slot function, eg .:

Code:
msg_on_newMessange(type, &slotFunction);

My code:
Header file: messages.h
Parent file: parent.c
Child file: child.c

How can I do this ?

View 2 Replies View Related

C :: Program To Execute Foreground Process - Signal Handling

Feb 3, 2014

I am trying to create a program that would execute a foreground process. I have this code for the foreground process

Code:
#include <stdio.h>
#include <signal.h>
int main() {
int temp;
printf("We are in the current program

[Code] ....

And this is my main program

Code:
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int main() {
signal(SIGINT, SIG_IGN);

[Code] ....

My main program stops executing after the process "./scanf" executes and there fore does not print the line "How are You"...

I want to main program to continue executing after "./scanf" finishes. How to achieve that?

View 2 Replies View Related

C/C++ :: Setting Signal Handler - How To Access Class Member

Dec 4, 2014

I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem. My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members. I understand that compiler should know that this class instances will exist during all program execution. I have tried to set static member class Foo instance in another class , but this didn't solve the problem. How to correctly implement signal handling in such case.

Here is example of my code

class MyContainer {
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] ....

View 1 Replies View Related

C++ :: How To Access Class Member And Methods From Static Method (signal Handler)

Dec 4, 2014

I am writing my program on C++ language. I have one promblem. I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem.

My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members.

I understand that compiler should know that this class instances will exist during all program execution.

I have tried to set static member class Foo instance in another class , but this didn't solve the problem.

What is correct approach to do this. How to correctly implement signal handling in such case.

Here is example of my code

Code:
class MyContainer{
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] .....

View 4 Replies View Related

C/C++ :: Send Signal SEGV To Crash A Running Process In Windows To Dump Core

Jul 2, 2014

I need to do an equivalent of kill -11 <pid>(which is in unix) in windows.

I need to crash a process with SEGV so that it would dump core in windows. Is there any tool by which we can do this . Also is there any sample code through which we can achieve this .

In windows we have taskill which only terminates a process , but is unable to send a signal like SEGV to the process upon which it would terminate and dump core .

View 9 Replies View Related

C++ :: Errors With Unresolved Token And Unresolved External Signal

Jul 10, 2013

My program will not run because of error LNK2028 "unresolved token" and error LNK2019 "unresolved external signal" and I do not know why. My teacher says that I need to make the constructor and display functions display class variables in different formats, but I do not know what to do with that. Here are my 3 files:

Header take 2.h:

#pragma once
#include <iostream>
#include <string>
using namespace std;
class Heading {
private:
string company, report;

[Code] ....

Here are the errors:
Error1error LNK2028: unresolved token (0A0003C9) "public: __thiscall Heading::Heading(void)" (??0Heading@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)c:UsersOwnerdocumentsvisual studio 2012ProjectsClassLibrary2ClassLibrary2Source1.objClassLibrary2

[Code] ....

View 2 Replies View Related

C :: How To Put Value From Scanf Into Array

May 2, 2013

Code:

#include<stdio.h>
#include<windows.h>
int nr, i, array_new[10],n=0;
main(){
printf ("Insert number: ");
scanf ("%d", &nr);

[Code]...

I need put value from scanf into array. How make this: array_new[nr]?

View 8 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

When I do this:

Code:

#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] .....

But when I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] ....

Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?

View 2 Replies View Related

C :: How To Scanf To Integer Or Char

Feb 6, 2014

I have to make a program for school to evalute poker hand.I am not asking about the logic of the program,I am asking because I have to take the input from the console,five lines which can be the cards 2,3,4..10 and the problem is with J,Q,K,A ,because I dont know how to tell scanf to expect integer or char ? If I type J,Q,K,A the program crash ,

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved