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


ADVERTISEMENT

C++ :: Read Float Numbers From Keyboard And Store Them Into Array Of 10 Elements

Jan 10, 2013

I have to complete a project that i want to read float numbers from keyboard and store them into an array of 10 elements.! Every time that a number stored into array i want to compare with previous one if they have +-10 difference .. I want to keep only 10 elements into my array so every time that i give value a[0] replace a[1], a[1] replace a[2],a[2] replace a[3]. . . .and a[10] deleted.. So when all elements of the array are similar with +-10 values print out the array.!

View 1 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 :: 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 :: 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++ :: Read Input File Of Data And Store Them In Arrays

Nov 5, 2013

Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

Hours Pay Rate Employee Number First Name Last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();

[code]....

View 9 Replies View Related

C++ :: Read Input From User And Then Store In Structure Variable

Apr 6, 2014

My program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int DESCRIPTION_SIZE = 100, DATE_SIZE = 20;
struct inventory {
string description[DESCRIPTION_SIZE];

[Code] .....

I left out the other functions. The error reads "no matching member function for call to 'getline'.

View 6 Replies View Related

C :: Program To Read Data From USB Device Connected To System

Sep 26, 2013

I am trying to fetch data from the USB device(say pendrive) connected to the USB port of a system. I have attached code.c file which I have wriiten for the same purpose, please find it. Here I am able to open the device file and read some random raw data which is in the log.txt file (also attached to this mail). But I want it to fetch data like minicom/teraterm does.

What methods and libraries I can use to do it successfully and how can it be done.

View 2 Replies View Related

C++ :: Read A Text File And Store Contents Into 2D Array?

Aug 2, 2014

read a text file and store the file contents into a 2D array?

100 101 102 103 104 105
106 107 108 109 110 111
112 113 114 115 116 117
118 119 120 121 122 123
124 125 126 127 128 131

Here's my code:

const int ROWS = 5;
const int COLS = 6;
int array[ROWS][COLS];
ifstream inputFile;
inputFile.open("table.txt");

[code]....

When i run the program and try and display the array, it doesn't work.

View 1 Replies View Related

C++ :: Check Input And Store Value In Array

Nov 8, 2013

This program works but i need to build an additional loop that will re-prompt a user if his initial entry (int y_n) is other than 'Y', 'y', 'N', 'n'. For instance if a user tries to enter 'Yup', he will be prompted "That isn't a valid entry" and then re-asked to enter int y_n.

Note: If user answers Y he is asked to enter a value that is entered into an array. If the user at any point answers N, the program ends and final stats are cout.

#include <iostream>
using namespace std;
int main(){
char y_n;
int i = 0;
float input_value;
float myarray[100];

[Code] .....

View 1 Replies View Related

C++ :: User Input Loaded Into Array Of Elements

Mar 19, 2014

I am compiling using Microsoft Visual C++ and I am trying to create a program that ask's the user for 10 numbers, and these numbers will have to be loaded into a one dimensional array of 10 elements. I read up online as well as my book and looked at sample programs, then created mine which was similar to the sample programs I looked at, but the sample ones compile , while I get C2059 and C2061 Syntax Errors. I am new to programming so I understand it could be one small thing but I after looking over it I am completely clueless.

Heres my program:

Code:
#include
<iostream>
int
main()

[Code] .....

My program is also attached

View 5 Replies View Related

C++ :: Input Elements Of Two Dimensional Array In Same Line

Nov 4, 2013

I want to input the elements of a two dimensional array in the same line . So while giving input . when i press enter . it should remain on the same line ? HOW to do that ?

View 1 Replies View Related

C++ :: How To Store User Input In Character Array Through Getline

Jul 2, 2013

int main() {
char StudentName[4][10] = { "Hermine", "Paul", "Gertrude", "Leon" };
cout << "Student Names";
cout << "
Student 1: " << StudentName[0];

[Code] ....

This code work fine...but i want to take name from user..how i store it in character array through getline()..

View 6 Replies View Related

C++ :: Store User Input Then Display Array Contents?

Jan 10, 2015

I'm coding a hangman game. I'm trying to store user entries so i can output them to show the user what they have already entered. Problem is that it's not display anything at all.

I'm trying to store multiple characters of course, and then display all characters stored.

char guess[27]={0};
cin >> guess[26];
int hit=0;
for(int i=0; i<len; i++) {
if( guess[26] == hidden_word[i] ) {
hit++;
select_word[i] = guess[26];
if(strcmp(hidden_word,select_word) == 0) {

[code]....

EDIT: I also get the error - Stack around the variable 'guess' was corrupted. At the end of the game.

View 6 Replies View Related

C/C++ :: Array Of Structs To Store The Information From Input File?

Mar 10, 2015

I'm trying to read the data from a file i/o and put them into an array of structs. But when I run the program, it gives me a bunch of "garbage" as an output. my code and see

#include<stdio.h>
#include <stdlib.h>
#include<string.h>

[Code].....

View 7 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

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 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++ :: How To Store Elements In 2D Vector And Call Them Out

May 5, 2013

I am currently trying to implement a 2d vector to store x and y of type int.

I have successfully passed it to the function, however i am unable to store the values in it. It always returns with a segmentation fault and my program terminates from there. May i know how do i store them properly and call them out?

Below is my code snippet

int reconstructSecret(int x, int y, vector< vector<int> > &inVec ,int constructSecret) {
int getX,getY,formula,accum,count,getSecret,startPosition,nextPosition,numerator,denominator;
getX=x;
getY=y;
int result;

[Code] .....

The main method

vector< vector<int> > inVec;
for(int i=0;i<constructSecret;i++) {
cout<<"please key in the "<<i<< "share of x value:";
cin>>x;

[Code] ...

View 9 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++ ::  Algorithm To Read Duplicate Array Elements - Return First Duplicate Value Only

Oct 23, 2014

I have an algorithm which uses nested for loops, which looks for duplicate elements in an array. However, as soon as one duplicate element is found... the program will stop looking for more duplicates? My program continues to look for more even though one is found? I know there is a break command but I can't get it to work. Code is below:

output of program: Repeating element found first was: 2, 1

Although I want the outcome to be; Repeating element found first was: 2

#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
void printRepeating(int arr[], int size) {
int i, j;

[Code] .....

View 6 Replies View Related

C++ :: How To Access Certain Elements And Store Multiple Inputs

Jan 20, 2014

am trying to create a program that asks the user personal questions.

std::vector<std::string> name, age, favsinger;
std::cout << "Hello, what is your Name Age Favorite_Singer? ";
std::cin << name; //i want to store the user's info along with the sibling's

[Code]....

View 4 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++ :: Class Memory Allocation - Store Number Of Elements In Table

Mar 31, 2013

Say I have a class with a few member functions, and only two data members: an int* Table; and an int Size;, to store the number of elements in Table.

I'm using a copy constructor that takes in two parameters: int* table, int size. In this case, is the address that table points to the same address as the object that table is part of? And furthermore, is it possible to say table.Size? I want to compare the passed array's size to the passed size.

View 2 Replies View Related

C++ :: Incorporate Array Of Structures To Read User Input Then Reprint That Information To Screen

Nov 18, 2014

I have to create a program that incorporates an array of structures in order to simply read input from the user and then reprint that information to the screen. This is a fairly simple problem, but the issue is that the professor requires that we solve it in a very specific way.

I must have three functions in total: one to receive input from the user, one to print the received values, and of course the main function which calls the other two. Also, the input and output functions must be defined using the following prototypes:

void inputData(Component C1);
void printData(Component *C1);

Where Component is a structure defined above as:

typedef struct// Component {
float cost;
int code;
char name[30];

[Code] ....

I know that this problem could be easily solved by simply passing the entire 'comp' array to the inputData function, or passing a pointer to it, or having it return a pointer, but I am not allowed to do any of these things. I must use the function as defined by the prototype.

View 3 Replies View Related







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