C :: Printf And Scanf - Output String Data At The End Of The Line
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
ADVERTISEMENT
Jan 24, 2013
Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?
View 2 Replies
View Related
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
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
Oct 17, 2014
I have "hello world" set for command line args.
int main(int argc, char **argv) {
printf("%s %s", argv[1],argv[2]);
}
That code produces
w
r
d
Why would it do that.
View 2 Replies
View Related
Apr 18, 2014
My goal is to read a one line file of a comma separated numbers into a floating point array. The numbers have up to 25 positions after the decimal. I'm having two issues with the following code.
1) atof() seems to be returning zeros every time. Why?
2) The last number includes the new line character. How do I get rid of it?
Note that I adapted the scanf command from here: The power of scanf() - [URL], and don't completely understand it.
Code:
#include <stdio.h>
#include <math.h>
//The following will be calculated in the real program.
#define DIM 1
#define N 8
int main()
[Code]......
In the "real" program, N is calculated and known before reading in the file and the file will always have 2 times N numbers.
View 9 Replies
View Related
May 6, 2013
I have the following line of the code. Now I want to save the content to a string. Is there a quick way for me to do the conversion using the same arguments/codes of printf?
printf ("Some different radixes: %d %x %o %#x %#o
", 100, 100, 100, 100, 100);
View 3 Replies
View Related
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
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
Mar 7, 2014
How can a mulitline string be read line by line
ex: str = "PERIOD="week"
DAY="day"
TIME="time"";
View 2 Replies
View Related
Jun 27, 2014
I'm reading strings one after another and trying to split it using strtok_r. This doesnot seem to be working
I have a .gz file from which I'm reading the data into the buffer in chunks.
The below code works fine only for the first chunk on data. Later it just breaks out.
while(1) {
char buffer[SIZE];
int bytes_read = gzread (f, buffer, SIZE - 1);
[Code] .....
View 3 Replies
View Related
Jul 2, 2013
I have an external file with one column of data. If I have a counter value let say counter =1, and counter++ and so on. How I can write such a c++ code that if the value of counter and value from the external file are same then generate an action let say cout both values i.e. value of counter and value from external file.
for more information, here is an example:
data in file(in one column): 2 6 8 9 10...
value of counter : 1 2 3 4 5 6 7 8 9...
then cout values only if value of counter and value from the file is same.
Here is my code so far, but it does not seem to work;
#include<iostream>
#include<fstream>
using namespace std;
int main() {
const int SIZE = 10; //Size declaration of array
int hours[SIZE]; //Array declaration
[Code]...
View 12 Replies
View Related
Jul 5, 2013
I have a text file (test.txt) with the following data:
01,05,25,20130728
01,06,25,20130728
01,07,25,20130728
01,08,25,20130728
01,05,25,20130728
01,05,25,20130728
01,05,45,20130728
01,05,65,20130728
01,05,85,20130728
01,05,35,20130728
01,05,25,20130728
01,05,35,20130728
I want to read this to one string called line. So far I have this code:
string line;
ifstream myfile ("/home/Test.txt");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile, line);
for (int a = 0; a <= 335; a++) {
cout <<line.at(a);
} }
myfile.close();
}
so far its only printing the first line and then throwing an instance of 'std::out_of_range'
View 2 Replies
View Related
May 12, 2014
I have to read the information about logic gates from a file. The file format is shown below:
Code:
gateOne = NAND(inpA, inpB)
gate2=NAND(1,2)
3 = NAND(23,25,26)
As, it can be seen from the above structure that whitespaces are not same everytime. So, to deal with this situation, i am using boost library to remove all whitespaces from the line which is being read and then try to find the name of gate and its input. My code is given below which is able to correctly find the gate names and its first input...but my code is not able to find the second, third and so on input names.
Code:
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <boost/algorithm/string/erase.hpp>
[Code] ....
View 3 Replies
View Related
Sep 28, 2013
printf is a part of code segment but found in data segment.....why is it so ?
View 7 Replies
View Related
Apr 4, 2013
I'm not too sure why I'm missing a line from the output. I've been going over my code like crazy and something seems to cause a line which would be size = 0: [nothing here] missing in my output. Here's my code:
Code: class binSTree: public binTree<T>{
public:
void insert(const T& x); //insert node with value x
bool search(const T& x); //searches leaf with value x
[Code].....
Other files are included but they are 100% correct as I used them in my past couple of assignments. The public version of remove is suppose to call the search function and determine the result of the search for a leaf with value x. Calls private remove and returns true. Otherwise it returns false if the search isn't successful.
View 5 Replies
View Related
Feb 5, 2013
void printList(int list[],int cnt,int numsPerLine){
for(int i=0;i<cnt;i++){
cout<<list[i]<<" ";
if((i%numsPerLine)==0)
cout<<"
";
} }
So cnt is 20, numsPerLine is 10, and list[] is initialized with a const = 20
i%numsPerLine on the first loop equals 0 and thus outputs a new line.
I'd like it to new line after 10.
View 1 Replies
View Related
Jun 10, 2013
I have been trying to make a small program that I will be using in a larger program that will make the user press space to see the next line of output.
Not exactly sure what I'm doing wrong, but I'm pretty sure that I need to put the space that the user would enter into an output file, and the read the input file
It runs, but it doesn't allow me press space before showing the next line.
I added a getline(cin, charVar) before, but I got a whole bunch of errors.
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <fstream>
using namespace std;
// function for dialouge
[Code] ....
View 4 Replies
View Related
Aug 10, 2014
Taken from Accelerated C++ book, I modified those code to use getline() instead of std::cin >> only to find out that the output has extra line. Why is that so?
#include <iostream>
#include <string>
int main() {
std::cout << "What is your name?" << std::endl;
std::string name;
[Code] .....
What is your name?
Naruto
*****************
* *
* Hello, Naruto
*
* *
*****************
Notice one asterisk after the greeting where it should be in the same line as the greeting.
View 4 Replies
View Related
Aug 3, 2014
I am having an issue with the statement "Both the input and output files' names should be read from the command line." I don't understand what this means or what I need to do.
View 4 Replies
View Related
Feb 13, 2013
I am suppose to make a program that will output a line for a specific age group,but everytime I execute the exe file it gives me the desired line and also the last line included everytime.Where did I go wrong with it including the last line everytime?
#include <iostream>
using namespace std;
int main() {
double age;
cout<<"Enter your age:";
cin>>age;
if (0<age && age <6)
[Code] ......
View 1 Replies
View Related
Dec 3, 2014
write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use a character array to store the string.) Does this follow the criteria? This program is very similar to one I found on these forums but I have one problem, it outputs everything backwards! EX: dogs will output to SGOD. What I need to do to make it output correctly, I think it may have to do with getline?
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main() {
char let[100];
cout << "Enter what you would like to be UPPERCASE: ";
[Code] ....
View 2 Replies
View Related
Jul 23, 2012
How to read a line with maximum of 8 bytes from a line in a file.
Let say line has 10248 bytes in one single line and same repeats for remaining lines in the file.
I need to read the first 8 bytes of a line and go on read the last 2 bytes of the line and repeat the till end of file.
View 3 Replies
View Related
Dec 26, 2013
I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...
i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....
------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";
[Code] ....
When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.
The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.
I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.
When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..
input = input / BASE; I get C9 where I expected to get 48.
My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?
View 6 Replies
View Related
Mar 27, 2014
Suppose, I have point_c, line_c and block_c three classes:
class point_c {
public:
double x, y;
};
class line_c {
public:
vector<point_c> Pt;
[Code] ....
As you can see, lines are composed of many points, and blocks are composed of lines and points. And I defined some member functions, so that I can add points or lines as required by line and block.
But, here comes the problem, if I use line.insertPoints(), or block.insertPoints(), the points will be stored in line or block. That is not what I want.
I want have a single place to store all points, a single place to store all lines, and a single place to store all blocks.
Then I guess I need some global variables
vector<point_c> Pt;
vector<line_c> Ln;
vector<block_c> Bk;
And I should change the classes into:
class point_c {
public:
double x, y;
};
class line_c {
public:
vector<size_t> PtIndex;
[Code] .....
in this way, the member functions will create the real entities into the global vector and set an index pointing to that entity. But this approach just make me feel it is not OOP anymore. when people using these classes, they got be careful about the global variables.
View 7 Replies
View Related
Aug 14, 2014
How can I read this file in to my struct?
12345Joe Lim KH879.00
12233Kay Suet Yee35.98
23781Leong Jing Yang 10.00
67543Woon Tian Yi500.50
struct master {
unsigned short int IDnum;
[code]....
not working
View 16 Replies
View Related