C :: Getting Integer With Only Using Getchar Function

Nov 16, 2013

I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer. And I cannot use strings or arrays.

View 4 Replies


ADVERTISEMENT

C :: Swap Chars Using Getchar

Sep 23, 2014

This is for homework . Must use only getchar and putchar

Code:

int main(void) {
int pch; //first
int ch; //second

[Code]....

And it works , but i need to hit ENTER two times when i have 3,5,7... chars to print result.

View 6 Replies View Related

C :: Get Rid Of Space / Use Scanf Or Getchar

Sep 24, 2014

I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.

Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?

Code:

include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}

[code]....

View 6 Replies View Related

C/C++ :: Calculator That Uses Only Getchar / Putchar

Mar 24, 2014

I basically just have to make a calculator that only uses getchar/putchar (printf is Ok for displaying errors) - Also, negatives must be error-checked. As of right now, my program will only work if there is exactly one space between the number, operand, and other number. No spaces, or more than one space, will give me some very weird digits. I also need to display the numbers with putchar, and not printf (as I did below), but I just really wanted a working program.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
int add(int input1,char operand, int input2);
int subtract(int input1,char operand, int input2);

[Code] .....

View 12 Replies View Related

C++ :: Getchar - Return Assigned Value

Nov 9, 2012

Once again i hit a very simple problem i am unable to resolve. I using Visual Studio 2010, but am compiling for C.

This:

Code:
char i=45;
while(i=getchar() != EOF)
{

should imo work perfectly (yes, no real code, just to demonstrate the issue), but it doesnt. Getchar() always returns 0x01. Why is that? This, in contrast, works perfectly fine:

Code:
char i=45;
while(i!= EOF)
{
i=getchar();

Shouldnt an assignment always return the assigned value?

View 2 Replies View Related

C :: Making Calculator Program Using Only Getchar And Putchar

Mar 21, 2014

I have to make a calculator program that has 5 different functions (this is obviously the easy part, once all the input is assigned to their respective variables), which are addition, subtraction, mod, multiplication and division (negatives are not allowed, and must be error-checked; spaces must be ignored). I need to take the equation from the user, echo it back and then solve the problem.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

[Code].....

View 4 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++ :: Why Function Is Not Returning Integer 1 Or 0

Nov 14, 2013

why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/

#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));

[code].....

View 2 Replies View Related

C++ :: Function That Get Length Of Integer?

Nov 23, 2013

Any good function that get the length of an integer in C++

I do know of str.length(), however i want something similar for integers

View 1 Replies View Related

C++ :: Pulling Integer Sizes Within A Function?

Feb 7, 2013

I'm trying to find the MAX and MIN integer sizes that are entered in by the users. I know that we need to sort [i] and [j] in my function to figure out which is the highest and lowest score correct?

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

[Code].....

View 4 Replies View Related

C++ :: Function That Returns Integer Value And Displays It

Mar 8, 2013

Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.

View 3 Replies View Related

C++ :: Function Not Finding Largest Integer?

Feb 10, 2013

My code compiles fine but it doesn't seem to want to calculate the max integer. It calculates min and average fine but I'm not seeing what is wrong with my code. The max integer keeps coming out wrong.

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cstdlib>
#include <algorithm>
using std::swap;

[Code] ....

View 1 Replies View Related

C/C++ :: How To Return Array Of Integer From A Function

Apr 2, 2014

The problem is how to return an array of integer from a function?

I'm writing a C program code to return an array of integers ( grades of students ) to the main function!

View 9 Replies View Related

C :: Why Integer With Array Change After Passing Through The Function

Apr 12, 2014

Code:

#include <stdio.h>
void define (int integer, int IntArr[0], int *IntP);
int main(void)
{int integer = 0, IntArr[1] = {0}, IntP = 0;
define(integer, IntArr, &IntP);

[Code]...

Why does the integer with array change after passing trough the function and the normal integer doesn't? (I know why the normal one doesn't, but I dont get the array one)

View 1 Replies View Related

C++ :: Function That Accepts Integer And Returns A String?

May 5, 2014

How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".

To do this would I just use an array?

View 4 Replies View Related

C++ :: Create A Function With Integer Number As Parameter

Jun 20, 2013

I must create a function with a integer number as parameterThis function use the parameter for a loop...example

n = 1
output
1
2
3

n = 2
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3

View 1 Replies View Related

C++ :: Function That Stores Number Into Integer Array?

Apr 30, 2013

I'm writing a function that stores a number into an array. If the number is greater that the lowest number in the array then it replaces it. The array size is 10. When the number is stored in the array. The lowest number must then be remove.

View 3 Replies View Related

C++ :: Function Which Take An Integer And Return Number Of Digits In It

Jan 31, 2013

I want to write a function which take an integer and return the number of digits in it i.e

int i = 123456
func(i) {
some code
}

output
the number of the digits are 6

View 9 Replies View Related

C++ :: Function To Receives Integer Array Along With Its Length

Apr 2, 2014

How to write a function that receives an integer array along with its length. the function calculates and returns the sum of the squares of all the odd numbers in the array?

View 2 Replies View Related

C :: Create Array Of Integer - Function Call In Main

Feb 2, 2015

I'm writing code to create an array of integer and let user input choice to display, replace, add new element, etc.I created a header file in the header file there's a function:

Code:

int display_one_element(int* array, int num_of_elements, int position) {
if(num_of_elements < position || position < 0) {
printf("Position out of bound.
");
return 1;
}
return array[position-1];
}

in main I write a function call:

Code:

display_one_element(array, *p_num_elements, position);

My code seems to work fine but there's an error message right next to my function call:
1.too many arguments provided to function like macro invocation
2.Expression result unused

I tried to move the function from header file to c source file. but other functions in the header file works fine and this doesn't work with the error message.

View 3 Replies View Related

C :: Output Smallest Integer Entered - Loops / Function

Oct 22, 2014

I am trying to find a way to put a getSmallest function in here so that it will output smallest integer entered. If it is just an arbitrary amount of #'s and I don't know what will be entered I am confused. Both on how to do it and how to link my function to my loop.

Code:
/* Prompts user and gets integer numbers from keyboard, one number at a time. Ends program when 99999 entered. and displays various results.
Written by:
Date: 10/20/14
*/
#include <stdio.h>
#include <stdlib.h>

[Code] .....

Could I take this and just replace all variables a, b, and c with getNumber, where would I link/declare smallest?

Code:
/* ==================== smallest ======================
This function returns the smallest of 3 integers.
Pre given 3 integers
Post the smallest integer returned
*/
int smallest (int a, int b, int c) {

[Code] ......

View 1 Replies View Related

C++ ::  In Function Assignment Makes Pointer From Integer Without A Cast

Jul 4, 2013

The log file gives me: In function ‘memFileAlloc’ assignment makes pointer from integer without a cast..When compiling the drivers for the Matrox card in the DL580. The offending code is:

STACK_LINKAGE MEMHANDLE memFileAlloc(
UINT32 dwSize,
const char* pszFileName,
int iLine) {
void* pvChunk;
#if MEMORY_STATS

[code]...

I think the offending line is:
pvChunk = ClientMemAlloc(dwSize + sizeof(UINT32), NULL)
because that's what the log file tells me.

The system is a 16 core HP DL580 G4 with 8g RAM, RAID 0, Mandrivalinux 11.0 and the display is a Matrox Parhelia 256PCIx.

View 11 Replies View Related

C++ :: Recursive Function - Printing Integer With Decimal Separators

Apr 7, 2013

I am trying to solve the following task:

-Write a recursive function that prints an integer with decimal separators. For example, 12345678 should be printed as 12,345,678.

The problem is that I don't know how to modify the integer in such way. I was thinking to convert it into a string, do an algorithm and then turn the string back to integer.

How to do such modification.

View 9 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C :: Write A Function That Finds Integer In Array And Returns Its Corresponding Index

Mar 20, 2013

I have an assignment which requires me to do the following:

Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:

- The first parameter is the array to be searched
- The second parameter is the integer to be found within the array
- The third parameter is the size of the array
- The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.

Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)

Code:

#include <stdio.h>
#define SIZE 10
size_t findNumber(int *sort, const int array[],int key,size_t size);
int main(void){
int a[SIZE];
size_t x;

[code].....

View 1 Replies View Related

C++ :: Linked List Set Function - Forbids Comparison Between Pointer And Integer

May 5, 2014

I'm trying to write a function called 'set' that sets the value of the i'th cell to val on my linkedList, and then returns the previous contents. I am stuck on it due to compiling errors:

This is my Node struct:

#ifndef NODE_H
#define NODE_H
#include <iostream>
template <typename T>
struct Node {
friend std::ostream &operator <<(std::ostream &os, const Node<T> &node) {

[Code] ....

The following is my set function:

template <typename T>
T set(Node<T> *head, int i, const T &val) {
for(int n = 0; n < i; n++)
if(head == val) {
val = i;
} return val;
} #endif

When I try to call it in the main() I get these errors:

node_utils.h: In function ‘T set(Node<T>*, int, const T&) [with T = int]’:
node_demo.cpp:26:38: instantiated from here
node_utils.h:161:2: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
node_utils.h:162:3: error: assignment of read-only reference ‘val’

So, I understand that I can't compare head & val on my if-statement -- But what do I do?

View 7 Replies View Related







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