C++ :: Input Three Names And Print Each One At Different Line
Dec 10, 2014We need a program that takes three names ( first middle last ) and print it each one at a different line...
View 5 RepliesWe need a program that takes three names ( first middle last ) and print it each one at a different line...
View 5 RepliesI 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 RelatedI need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have
Code:
#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")
[code]....
Just working up for the google coding contest to start soon and have been practising some of the test questions however i make correct algorithms but my output is rejected because of the fact that my strings are printed on a new line so i wish to know a method to print strings using a printf statement or any other function on the same line ...
View 3 Replies View Related//Build a program that uses a single-dimension array to store 10 names input by a user.
//After inputting the names, the user should see a menu with two options to sort and print the 10 names in ascending or descending order.
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char names[10];
char temp[10];
int count,i,j;
int sort;
[Code] .....
Here is a code snippet which is a bit annoying.
Code:
cout << "Put in the names of people, press q to exit" << '
';
while((cin >> people_inp) && (people_inp != "q")){
Person *p = newPerson(people_inp);
[Code] ....
The problem of this code is when you put in the names(via cin) and press enter command prompt will disappear. What should I do so that Command prompt will not disappear after I input some names? I mean it disappears without you pressing a key.
I have a lab with the following instructions:
Manually create an input text file called Lab22BInput.txt with the following data:
Dove
Doe
Alston
Zebra
Egg
Write a program that will read the names from the input file. Print out each of the names read to the screen. The program should go through the list of names and determine which comes 1st in the alphabet. The program should determine how many letters are in this name. Print out the name that comes first in the alphabet and the length of the name.
I have created the input file, and the data correctly outputs to the screen when I run the program. However, I do not know what kind of logic to use to sort them alphabetically and determine the amounts of characters.
So far I have the following:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str1, str2, str3, str4, str5;
[Code]...
The textfile babynames.txt, which is included in the books website, contains a list of the 1000 most popular baby names of boys and girls. Write a program that allows the user to input a name and the program should then read the file and search the matching names among the boys and the girls. If the name is found it should output the name and the names rank. It should also indicate if their is no match. How to start this.
View 1 Replies View RelatedIn my class we were supposed to write a program from the book that inputted the names and votes and the program is supposed to spit out who won the vote. I did this then while i was reading the assignment from the instructor I noticed he wanted the information inputted from a TXT file instead of manually inputting it. I cannot seem to get it to work....
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define N 5
char names[N][20];
float votes[N];
[Code] ....
here is the txt file
Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800
The code I have is below. Im able to print them all onto one line but I need to print 10 per line separated by commas and Im not sure how to do that ):
for (int i = 0; i < MAXVALUE; i++){
for (int j = 0; j < counts[i]; j++){
output << i << ",";
I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :
For i = 3;
Text[0] : I learn class String#
Text[1] : I dont learn class String#
Text[2] : String#
It print me like that : Text[1] :
I dont learn class String More than that look at the next example :
For i = 3;
Text[0] : I learn class String#abcdef
Text[1] : I dont learn class String#
Text[2] : String#
You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :
Text[1] : abcdef
I dont learn class String
#include<iostream>
#include<string>
using namespace std;
int main() {
string text[100], cuvant;
int i, j, m, lung = 0;
cout << "
[code]....
I am using C++ to write data into a (.ini)file. However, when I try to print the value '0A' I am getting '0D 0A'. (this is what I see when I copy the output to HexEdit). From what I can figure out, '0A' is the ascii for 'new line' so write function automatically adds the '0D' which is 'carriage return'. What I want is to print 0A alone. how can I do this?
Note: Windows it is working fine, but linux it is not working...
unsigned char arrRes[4];
int N = 10;
memcpy(arrRes,&N,4);
std::ofstream Output(LUT_OUTPUT_FILE_BINARY,std::ios_base::binary | std::ios_base::out);
Output.write((const char*)arrRes, 4);
here 10 means 0x0a but it is printing 0d,0a...
I'm having problems fully comprehending how to do this task (I'm only going to include my function code since that's the basis of my problem). How should I go about getting my vector to print off 12 items per line. Here's my current function.
void printVec(const vector<int>& v) {
for(unsigned i=0; i < 12;i++)
cout<<v[i]<<" "<<endl;
}
I'm trying to enter an 'x' and 'y' coordinate on only one line separated by a comma. But I keep getting a syntax error. Here are the lines of code I'm using. This has to be simple. What am I doing wrong with this code?
Code:
cout<< "Please enter the x and the y coordinates of the first point,"<<endl;
cout<< "use a comma to separate them. " <<endl<<endl;
cin>> "You entered: " >>x1>>",">> y1 >>"for the first point" >>endl;
The problem is with the first "Type and Run," where the code looks like this:
Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
[Code] ....
I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:
Code:
print_it.c: In function "main":
print_it.c:36:15: error: "stdprn" undeclared (first use in this function)
print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in
print_it.c: In function "do_heading":
print_it.c:49:16: error: "stdprn" undeclared (first use in this function)
I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:
Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
[Code] .....
It compiled OK with the gcc compiler but I only get this when I run the program:
Code:
Proper Usage is:
print_it filename.ext
I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.
Questions:
1. What should be done to make this program run?
2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?
I have written the following code but i am stuck. Write a program that will prompt the user for a file name and open that file for reading. Print out all the information in the file, numbering each new line of text.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21], c;
int i = 1;
FILE *inFile;
[code]....
I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include <vector>
using namespace std;
int main(){
vector <string> words;
string str, paieska;
[Code] .....
How to print line(s) where I found that word?
i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.
void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}
I want to be able to read 2 line input, then safe them in separate arrays.
line1 input=array1
line2=array2
I am trying to get my input from user in the same line with certain width between but my output is not in the same line. my third variable which is fruit[i] is shown one line below . How I can fix this ?
#include <iostream>
using namespace std;
int main () {
int staff[3] , fruit[3];
[Code] ....
How to input two variables in the same line? Like when i type 12 and press enter, 1 must be assigned to a, and 2 must be assigned to b. I want it to be entered on the same line, and press enter only once. How do i do that?
View 5 Replies View RelatedI want the phrase "BUY TICKET" to trigger something, i'm thinking an if statement, and then assign the number after the phrase to another variable. There will also be other commands entered from the input file such as "BUY RAFFLE' "TOTAL REVENUE" on the following lines. Sounds like I need to compare a string(?) to a constant phrase, and if they match have it run the specific code?
Code:
//scan in from file
fscanf(ifp, "%c", &input);
if (input == 'BUY TICKET'){
//Run this
}
How to do it using the tools in C.
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].....
I am trying to use the command line to put a txt file in this code. I do Project->set project arguments in code blocks and nothing happens. How does one set up the arguments and where do i do it in codeblocks?
Code:
int main(int argc, char *argv[]) {
char name[20];
struct artist *ptr;
char lineBuffer[LINEBUFFERSIZE];
artistNodePtr startPtr = NULL; /* initially the artist list is empty */
FILE *musicFile;
char *artistTemp, *discTemp, *yearTemp, *trackTemp, *songTemp;
[Code] ....
I have three questions concerning the below code I have written, which is expected to do basically as the attached diagram illustrates:
Code:
#include <stdio.h>
#include <stdlib.h>
double getAverageGrade(int studentGrades[] , int size);
int* getStudentInfo(int * numCourses);
int main()
[Code] ...
(1) How may I display the averages to 2 decimal places, namely why doesn't %.2lf work? The program gives 89.00 for 89 and 90, for instance.
(2) How may I read the number of courses and the relevant grades in a row for each student?
(3) How may I free (de-allocate) my array of pointers, namely grades? Does it suffice to use free(grades)?
I'm new to C/C++. I am attemping to use fgets and sscanf to read a line of input, and confirm it is a positive number.My code works great, except for the case of a negative number. When I enter a negative number, my while loop seems to run infinitely, with stdin providng the same input over and over again.
Here's the code snippet:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define TEXT_LEN 64
void foo() {
char* inStr = (char*)malloc(sizeof(char)*TEXT_LEN);
memset(inStr, 0, TEXT_LEN);
}
[code]....