C :: Inputting Data From Multiple Lines Using Scanf?
Aug 1, 2013
How would I go about inputting data from multiple lines using scanf?
So far I have tried a loop and somehow checking for '' but can't seem to figure it out..
E.g I want to be able to scanf the ints below line by line and print them( if that makes sense) .
5 15 20 30 5 6
5 6 8 20 34
5 6 7
5 2
2 6 7 2 1 6
This is what i've tried so far, but am really lost!
Code:
int input;
while(scanf("%d", &input)){
printf("%d",input);
if(input == '
'){
continue;}}
View 13 Replies
ADVERTISEMENT
Mar 18, 2013
how to use EOF to terminate inputting data
View 1 Replies
View Related
Apr 19, 2014
So I have a two-dimensional array named temperatures[7][2] and I am trying to promt the user to input the highest temperatures for a 7 day period in the first column and the lowest temperatures in the second column. So far all I am getting when I test my code is the temperatures in the second column.
/*Intermediate23.cpp - This program inputs the highest and lowest temps. for seven days. It then displays the average high and low temps. and also diplays the highest temp. that's stored in the first column of the array and displays the lowest temp. stored in the second column of the array.*/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//Declare array and variable
int temperatures[7][2] = {0};
int avg = 0;
int totalTemp = 0;
[Code] ....
View 4 Replies
View Related
Mar 31, 2014
Code:
scanf("%d", &a);
printf("A");
scanf("%d", &b);
prints "A" after calling scanf two times instead of between the calls (first scan, then print, then scan). I'm using GCC v4.6
View 7 Replies
View Related
May 17, 2014
I'm trying to load a file that look like this:
IP:123.123.123.123
Port:12345
I can't figure out how to load multiple lines. I tried using , but I can't get it to work. Is there a better way of doing it than I am right now? This is my code.
char message[100];
int messageCount = 0;
for(unsigned int i = 0; i < file.size(); ++i) {
message[i] = file[i];
[Code] ....
View 1 Replies
View Related
Oct 13, 2013
int statarray[] = {61, 66, 47, 50, 372,
62, 66, 47, 50, 372, 50, 54, 64, 45, 331, 49, 52, 58 69, 356,
58, 80, 50, 48, 389, 76, 64, 60, 59, 401, 76, 59, 57, 54, 422,
53, 45, 45, 52, 253};
I'm getting a bunch of different errors with this, how do we do this?
View 2 Replies
View Related
Aug 26, 2014
I am trying to convert multiple lines of strings to double with std::stod .... I used the code found on the website:
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
int main() {
std::string two_doubles =" 22145.365 -3564789";
std::string::size_type K;
double first = std::stod (two_doubles, &K);
double second = std::stod (two_doubles.substr(K));
}
The string starts with white spaces. I get this error message when compiling:
warning unused variable 'first'
warning unused variable 'second'
How do you convert the two numbers in the string two_doubles to doubles?
View 2 Replies
View Related
Apr 12, 2014
This code i made is a cent converter from 5 to 95 cents. The problem i'm receiving is when the 'cents' function is sent back to the 'main' function it only prints one line. It seems to just print the first if construct that complies with the statement. Is there anyway i can have this function print multiple cent values? For example if 60 cents was entered it would only print '50c', and i want it to print '50c' and '10c' instead.
Code:
#include <stdio.h>
int x;
void check(int x)
{
if( x < 5)
printf("Less then 5 cannot be calculated
");
else if(x > 95)
[code]....
View 3 Replies
View Related
Jan 31, 2014
I am trying to make a messageBoxButtons dialog with the 'yes, no' buttons. Im having trouble because of the multiple lines and parameters already in the message, this means that when i declare the messageBoxButtons.YesNo and the title - it throws an error because of the multiple lines etc...
How can I get the yes/no message box to work in this instance?
class Output {
string text; {
DialogResult dialogResult = MessageBox.Show("Please make sure the following information is correct before submitting."
+ " Date: " + Date
+ " Hours worked: " + Hours
+ " Hourly rate: $" + Rate
[Code] ....
View 5 Replies
View Related
Jul 28, 2013
I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines.
I have created rectangle region for each line and trying to move the line.
When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen.
How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC.
View 4 Replies
View Related
Nov 12, 2013
this is a syntax i've been trying to run. apparently it stopped as i entered the first value. this is the value i am trying to key in
Initial House Cost 67,000 62,000 75,000
Annual Fuel Cost 2,300 2,500 1,850
Tax Rate 0.025 0.025 0.020
my syntax are as below
Code:
#include <stdio.h>
#include <conio.h>
int main(void) {
float houseInt1 , houseInt2 , houseInt3 ;
float fuelAnnual1 , fuelAnnual2 , fuelAnnual3;
float taxRate1 , taxRate2 ,taxRate3;
float total1 , total2 , total3;
[code]....
View 9 Replies
View Related
Dec 2, 2013
I'm trying to get this programme to work but I can't get it to output the string data at the end of the line.I have copied and pasted the line in question below but it may be a prob with the prog further down.
It reads character input ok but doesn't put one string into another or recognize when a string is quoted in a printf.
Code:
printf("%s what is your second name?
", surname, name2, name);
#include <stdio.h>
int main ()
{
char name[20];
[Code] ....
View 8 Replies
View Related
Apr 16, 2014
Using cin.sync() works great so far, but my program still breaks if you copy something with multiple lines into the console.
string test = "";
while(true) {
cin.sync();
getline(cin, test );
cout << endl << "test: " << test << endl;
}
However, if you were to copy this:
1
2
3
and paste it into the program, the output would be1
2
3
test: 1
test: 2
And if you press enter one more time:1
2
3
test: 1
test: 2
test: 3
The 3 finally pops out.
View 2 Replies
View Related
Mar 30, 2014
For a project we are given a file with a couple of thousand lines of values, each line having 9 different numbers.
I want to create a for/while loop that, for each loop, stores the 8th and 9th integer of a line as a variable so that I can do some calculations with them. The loop would then move onto the next line, store the 8th and 9th numbers of that line as the same variable, so that I can do the same calculation to it, ending when I've run out of lines.
My problem is less to do with reading the file, I'm just confused how I'd tell it to take only the 8th and 9th value from each line.
View 5 Replies
View Related
Jan 16, 2014
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
View 6 Replies
View Related
Sep 20, 2013
I have been attempting to store mathematical functions in a file by parsing them into a linked list with a variable sized char ** array as my storage device. I have ran into problems with the memory management detail. The program crashes before output is flushed to the console, so printf() wasn't a debugging option. Neither is my actual debugger, since it seems to get a SIGTRAP every time. I have my warnings turned all the way up, but no errors or warnings are appearing. The part I know works is the actual code that opens the file and gets a line from the file. As far as the two functions that implement the linked list, that is most likely where the problem lies. My current attempt is basically to store the size of the dynamic array in the structure and keep resizing it until there are no more tokens. Then I will store the number of elements of the array in the structure and move on to the next node.
Here is my text file I use :
Code:
sqrt( 25 ); pow( 6 ); sin( 2 );
pow( 4 ); tan( pow( 2 ) ); Main.c :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct file_data
[Code]...
View 7 Replies
View Related
Jul 11, 2014
I am trying to create a generic map container which shell contain data of different datatypes. I already found a solution in this forum here:
[URL]...
Introducing a container with a Base Class as content type and inserting objectes of Derived Class types from that Base Class suites my implementation very well. But it is not really working. I implemented it this way:
class MyType {
public:
MyType() {}
virtual ~MyType() {}
}; template <class PT> class ParseType : public MyType
[Code]...
Then I insert one element.
// index being an object of type Parser<string>
ParseType<string>* test = new ParseType<string>( index );
// and index.val(0) = "-n"
iMap.insert( pair< string, MyType* >( index.id(0), test ) );
Now I think I should be able to call
const string key("-n");
iMap.at(key)->content->val(n);
Or
iMap.at(key)->get_val(n);
But neither one compiles with the error that "class MyType" (as the map container is pointing to a MyClass object) has no member/member function "content"/"get_val".
I also tried introducing member and member function "content" and "get_val" in "class MyType", which I thought should be hidden while constructing ParseType<string>. This would compile but it does not call the member "content or member function "get_val" from class ParseType.
A second try was to remove templatization of "class ParseType" and introduce a specific, let's say, "class ParseString" for objects of type Parser<string>. But the problems remain the same either the compiler complains due to missing member/member function or retreiving the map content will not call the derived class member/member function.
View 4 Replies
View Related
Jun 17, 2014
Basically I do not want to use a menu, instead just accept either an float or a single character. Then send the data to the appropriate spot based on the user input. I have been unable to convert the char to a float, and even if I did the char would probably only accept the first digit, say user enters '15' it would only read the '1'. I've tried strings instead of char but then unable to use the isalpha function. Do I need a char[] and then iterate through to get the numeric data? Then how do i make '1' and '5' become 15. There is probably a solution. I've also tried to use a loop waiting for the correct data while(!(cin >> letter)) which works but how do I get out if the user enters number.
#include <iostream>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;
[code].....
View 3 Replies
View Related
Feb 18, 2013
I'm having trouble making a .obj loader at present I'm trying to load faces that are defined as follows:
f 1/1/1 2/2/2/ 3/3/3
So far I've separated the the three number groupings into three strings, I've had a few issues with stringstreams and would like a simple solution.
View 1 Replies
View Related
May 7, 2013
I am new to c++ programming i just want to know how to write the data into different files.Suppose my input files has 1-8 ids so each id data must be stored into each different file. And below is my code.
#include<fstream>
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include<list>
#include <math.h>
#include<conio.h>
#include<string>
#define PI 3.14159265
using namespace std;
double angle;
ifstream indata;
ofstream outfile;
[Code] .....
View 1 Replies
View Related
Mar 2, 2014
it skips the input phase,, instead of inputting the last name it goes directly to the firstname then middle initail and street name are working fine but it skips the street name then goes to city and so on....
Code:
char l[50], f[50], m;char strtname[50], cty[50], cntry[50];
int strtnum, zp, i;
system("cls");
printf("Enter Last name:");
gets(l);
printf("
Enter First name:");
}
[code]....
View 3 Replies
View Related
Mar 27, 2013
I have to write this program that is to store the name, address, id number, etc of a student. The data is supposed to be brought in through main and there will be multiple students. I'm not sure what commands I should use to bring it in.
EDIT: This will make more sense. In the .txt file the info will be written like
Name
Last name
Address
etc.
I need to input that and use that for the appropriate number of students.
View 1 Replies
View Related
Mar 15, 2014
We're working on classes in my programming class, and I have a question about function calls.
Bascially, I have all my set and get functions set up and ready to go.
I was wondering if it was possible to have the user input a variable while calling a function.
for example
cin >> getname();
the user inputs a value that gets passed into getname.
Or does it have to be something like
cin >> name;
getname(name);
mind you all, this isn't code from my program i'm just spitballing here.
View 4 Replies
View Related
Feb 7, 2014
My assignment : "Input the answer as the words true or false and put the user's answer in a boolean alphabetic variable."
My code:
bool T;
cout << "Type 'true' for lowercase or 'false' for uppercase";
cin >> T;
if (T == "true") {
cout << "Enter a whole number in decimal base: ";
cin >> dec;
cout.setf(ios::showbase);
cout << "Decimal " << dec << " to Hexadecimal with lowercase: " << setbase(16) << dec;
}
I'm not sure how to get 'true' as user-input as true for bool.
View 3 Replies
View Related
Sep 17, 2014
I am trying to make a table class that will be able to have multiple columns of data. I want it to have something to hold data (I was using a 2D vector for only one data type) in it, somewhat like a pair, but for any number of data types. The class is a template to make it generalized.
I have looked a little at variadic templates, but I don't know how to declare the vectors for each data types then.
View 4 Replies
View Related
Jan 24, 2014
I have to implemente the to_string method. Whats the fastest way? Stringstreams. But I have to use C++ without any headers, so I need to implement the stringstream class. How can an stringstream hold one float? An double? Hoq cqn I implement an strigstream myself?
View 8 Replies
View Related