C++ :: Reading Int Choice In With A String Buffer Instead Of Cin?

Sep 25, 2013

How do you read an int choice in with a string buffer instead of cin?

View 2 Replies


ADVERTISEMENT

Visual C++ :: Retrieving Size Of Each String In Order To Produce A New Buffer For Concatenated String

Feb 25, 2013

What is the efficiency of the two assignments (line 1 and 2), i.e. (function calls, number of copies made, etc), also the Big O notation. I know there are function calls for retrieving the size of each string in order to produce a new buffer for the concatenated string...any difference between line 1 and 2 in terms of efficiency?

String s("Hello");
String t("There");
1. s = s + t;
2. s += t;

View 3 Replies View Related

Visual C++ :: Reverse String Sequence In String Buffer

Apr 27, 2013

I made a simple little program that takes text from the clipboard, and spits out all the lines I've copied one at a time (so my program can analyze it).

everything works perfectly, except, it spits it own in the wrong order, I want it to spit out from bottom to top. but currently it spits out the data from top to bottom. here is my code :

Code:
#include <iostream>
#include <Windows.h>
#include <string>
#include <sstream>
using namespace std;
int main() {
HANDLE clip; // assigns the var. clip to hold a handle ID.

[Code] .....

I want this loop to run backwards! Like it say's what I want to work backwards. Where as I know how to flip a while loop like this: while(x < 5), how to flip a loop like the one I'm using. how I can do this?

View 8 Replies View Related

C++ :: Stream Buffer To Base64 String

Oct 2, 2013

I have problem with this code:

#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
#include "ScreenCap.h"
#include <wchar.h>
#include "base64.h"
#include <sstream>

using namespace Gdiplus;
int GetEncoderClsid(WCHAR *format, CLSID *pClsid) {

[Code] ....

This function return me a long series of Y ended with other chars but not the base64 string.

I think the problem is std::string encodedstring = base64_encode(buffer, dwBufferSize); but I can't figure out the problem.

The base64 function is: [URL] ....

View 2 Replies View Related

C++ :: Difficulty Appending Local Buffer Value With String?

Apr 13, 2013

how to combine a string value with a local buffer containing time and date. I can't seem to get the syntax correct or find an example of this.

So I'll have a result like: The time is: 12:49 04/13/2013. My project will put different values in String mess1 depending on what's happening.

My code

char buf1[20];
String mess1 = "The time is:";
sprintf(buf1, "%02d:%02d %02d/%02d/%4d", hour(), minute(), month(), day(), year());
//mySerial.println(buf1); // operates perfect
mySerial.println(mess1 buf1); // Does not compile - error: expected `)' before 'buf1'

I have also tried a comma between (mess1, buf1), no dice.

View 3 Replies View Related

C++ :: Randomized Multiple Choice

Feb 20, 2012

I have gotten my code sorted out, and now it works. But to be adaptable to 3pi robots, which I will be loading it into eventually, the user has to be given three letter (a, b, c) multiple choices for answer input to the math questions. The three choices have to be randomized everytime the program loops too. Currently it just runs on number input.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int menu();
void addition(int *Preward); // function to return truth values
void subtraction(int *Preward);

[Code] ....

View 4 Replies View Related

C# :: Multiple Choice Symptom Checker?

Mar 9, 2015

I'm doing a project through college which is a diagnostic and support tool for Windows OS's. The application at the moment has a simple expert system which is a Combobox with strings that relate to common PC problems. Then those strings are put through a switch statement and relevant commands are shown to fix the problem i.e. "My printer is not working" will disable all buttons except for printer management, spooler folder etc.

My supervisor who marks my project has said this isnt good enough and wants a more layered hierarchy approach so he's looking for 3-4 groupboxes with tickboxes inside them and users tick the boxes that relate to their problem which will give the functions to support. The only way I can see to do this at the moment is a massive nested switch statement that is really not worth the time. There are 60+ functions in my program so you can imagine how long the switch would be trying to pick and iterate through all of the possible answers.

I'm just trying to figuire out an easier way to do this, rather than a massive switch statement. Something like WebMD which has 4-5 tick boxes and can give out the same answer for different symptoms.

I've attached a Flow Chart I made of the hierarchy Im trying to go for [URL] .....

View 1 Replies View Related

C/C++ :: Tic Tac Toe Game - Creating A Menu/choice

Nov 11, 2014

Im trying to create something like a menu in a tic tac toe game. I want the computer to ask the user "who starts first" is it the X or the O who starts first? Then the user should type in either X or O but if he types something else i want to ask again .

this is what ive done :

int main () {
printf("
");printf("
");
printf(" %c | %c | %c
", board[1], board[2], board[3]);

[Code] .....

View 10 Replies View Related

C++ :: Program Menu Choice Skips Over Input

Jun 1, 2013

I just recently finished up a program that implements Dijkstra's Algorithm and I thought I would make a nice little menu for the user.

so the user can input their locations, I use Getline just in case their location contains spaces. However, when the user selects 2, It skips over the first input for the "Source" location and only lets the user input for the "Destination".

Any reason why this would happen? Am I missing something with Getline? Anyway, here's the code...

template <typename V, typename E>
void Graph<V, E>::Driver() {
bool done = false;
int menu(0);
InputFile();

[Code] ......

View 2 Replies View Related

C/C++ :: Assigning Variable From Multiple Choice Answer

Oct 29, 2014

I tried to create a multiple choice list and I want to assign the value of the answer option chosen by the user so I can use it later on in the code. Later on in the code i've asked how many people (p) want a drink and multiplied it by the chosen size to calculate the price c = p * n where c is cost, n is price and p is number o of people At the bottom i tried to assign parameters where depending on what option the user has chosen n will be assigned to the chosen value...

{
printf("SELECT TYPE OF PAINT:"); /*multiple choice of paint */
printf("1. Large ");

[Code]....

View 1 Replies View Related

C++ :: Multiple Choice Function - Using Character As Parameter

Feb 20, 2012

I have a multiple choice function below that is part of a larger program but I am having trouble having it operate with characters as inputs and arguments. It has to be a character input, but I kinda want it to act like an integer, how do i do that?

Code:
void addition(int *Preward) //function that is called by the users selection {
int random1, random2;
int order;
int one, two, three;
int rando1, rando2;
char a, b, c; // ERROR

[Code] ....

View 2 Replies View Related

C :: Create Multiple Choice Quiz Works But With A Warning

Apr 10, 2013

I am trying to create a multiple choice quiz so I can learn the menu at my new job, while doing a side project but I am having a warning when outputting. Speaking of side projects, is this a kind of side project people are looking for on a resume?

Code:

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

[code]....

View 8 Replies View Related

C++ :: Grading Multiple Choice Test - Getting Infinite Loop?

Nov 4, 2013

I am writing a program for grading a multiple choice test. The test data is pulled in from another file. My problem is that its only pulling in the first line of data and running an infinite loop without reading the next line of the data file.

My code is as follows:

PrintPurpose ( );
cout << student << " ";
cout << answers << " ";
inData >> key;

[Code].....

View 1 Replies View Related

C/C++ :: 5x5 Multiplication Table Starting With The Number Of User Choice?

Feb 23, 2014

#include <stdio.h>
#include <stdlib.h>
int n;
int m;
char input[20];
int num;
int main() {
int num0;

[code]....

I'm supposed to write C program that will generate a 5 X 5 multiplication table starting with the number of the users choice. The program is supposed to operate within a loop and run until the user indicates that they no longer wish to enter any more numbers. I can get the program to run but am wondering what I need to do to get the program to ask for another number and how to make the program stop when the user no longer wants to play. Should I start with "Do you want to enter a number" if yes, run back through loop if no, goodbye?

View 8 Replies View Related

C++ :: Generates Random Addition For Subtraction Depending On User Choice

Feb 17, 2012

Below is a program that generates random Addition for Subtraction problems depending on the user's choice. The user is prompted to input an answer and then it keeps your score. If you want to quit you just press zero.

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include <string>
using namespace std;
int menu();
bool addition(int &reward); // function to return truth values

[Code] ....

View 14 Replies View Related

C :: Food Calculator Doesn't Calculate - Choice Menus Not Display Properly?

Dec 7, 2013

I'm new to c i've been trying to write code everyday, and recently ive been reading a book and decided to write my own program with what ive learned with it, basicly you get a choice for how many different main courses you would like to have (right now you can only choose 1) and then you can choose which course you would like, it then asks for the amount of guests you would like and calculates how much food you will need to feed the guests. My code compiles but the program doesn't work properly

Code:
#include<stdio.h>

float guests;
float lbs;
int guest_att(guests)
{
puts("how many guests will be attending?");
scanf("%d",& guests);

[Code] .....

and this is how the program runs

Code:
Scotts-MacBook-Pro:learnc scott$ ./wed
how many main course choices will you have?
1

Please make a selection.
1. Chicken
2. Fish
3. Steak
invalid choice

Please make a selection.
1. Chicken
2. Fish
3. Steak
1
how many guests will be attending? 55

You need 0.000000 pounds of of chicken

Please make a selection.
1. Chicken
2. Fish
3. Steak
invalid choice

Please make a selection.
1. Chicken
2. Fish
3. Steak

View 3 Replies View Related

C++ :: How To Create True False And Multiple Choice Questions Using Text Files

Jan 7, 2015

So im trying to create a quiz using c++ that incorporates three different types of questions. These are the standard one answer question, true false questions and multiple choice questions.

How to create the true false and multiple choice questions?

One way that i came up with looks like this

Question A answer1 B answer2;

View 2 Replies View Related

C :: Reading Integers That Are In A String?

Dec 3, 2013

I am doing a program and i need to read integers that are in a string and i dont know if i am doing it correctly.

Code:
unsigned int j=0, h1;
char num[100] , str1[100], str2[100], a[100], b[100];

sscanf(str1, "%[^;] ; %[^;] ; %d ", a, b, &h1); the string is : "0048915433190;24/10/2013;13h 7m 47s;13h 8m 59s;0;1;"

And what i want to read with sscanf is the hours, minutes and seconds.

View 1 Replies View Related

C :: Reading Infinite String?

Sep 24, 2013

I have made a program that can take an infinite string:

Code:

#include<stdio.h>
int main(void) {
int i = 2, j = 0;;
char *string;
printf("Enter any string:

[Code] .....

But there is some problem in it, like its printing extra characters after string. reading infinite characters in a string

View 11 Replies View Related

C++ :: Reading Characters From String

Apr 13, 2013

i have a string which is n characters long. i need to read say 20 characters at a time, wait for the user to type OK and then send another 20 characters. wait for the user to type OK and send 20 characters again until we get to the nth character.

View 3 Replies View Related

C++ :: Reading String With Space?

Sep 26, 2013

how can I read some strings that contains spaces and put them in a vector of strings, using the push_back() function?

I have a collection of functions, for example: [multiply_by_forty two, add_by_five]. All I want to do is to store the strings like: multiply_by, add_by in a vector of strings, and the arguments:forty two, five etc in another vector of strings, but with spaces. The function convert() converts written numbers to numbers (for ex the output of covert("forty two")is 42;)

Here is the code:

public:void split() {
vector < string > s1;
vector < string > s2;

[Code].....

View 1 Replies View Related

C++ :: Reading TXT Line Into A String?

Sep 11, 2014

void login() {
//username, password, option to register, option to exit, link to website
cout << "Would you like to login(1), or press anything else to register.?" << endl;
cin >> loginYorN;
if (loginYorN == 1) {
cout << "Please enter your username: ";
cin >> accountInfo[1];

[code]...

So as above, I ask them to input 1 for login, anything else for register. Whatever they input, it get's stored into loginYorN, then I check to see what they input. If they put '1' for input, then I ask them for their username, store that into accountInfo[1], and then asking for the password, storing that into accountInfo[2].

Now here is where I need to input line 1(username) from login.csv or login.txt and line2(password) and storage these into accountID and accountPW.

View 1 Replies View Related

C/C++ :: Reading In A String And Turning It To Int

Dec 10, 2014

I have a problem with transforming a string, for example

"13 + 19"

and store this in a list as seperate integers,

list = {13, 19};

and another list with the +, -, /:

list2 = {+};

this is my function:

int evaluate(char* formula, int* result) {
struct List *listofintegers = list_create(); //creates a list, this is the structure:
/*
struct ListNode {
int value;
struct ListNode* next;

[Code] ....

This is how i execute my function in my main.c:

int value;
evaluate("19 + 16", value);

This is what i get in my prompt:

I will also have to seperate the +, - and / in another list,

I don't even know how i can get my string when char* formula is given as an argument...

View 2 Replies View Related

C :: Reading String And Checking If Integer

Nov 23, 2013

wrote this program to check if a string is an integer. It checks for + or - sign at the front of it, but it spat out some errors.I think I broke it.Here is the code:

Code:

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int getInteger(char*);
int main(void) {
char str[99];
int x;
}

[code].....

View 2 Replies View Related

C++ :: Error Reading Characters Of String

Feb 2, 2013

#include<fstream>
#include<Windows.h>
#include<cstdlib>
#include<iostream>
#include<string>
#include<iomanip>
#include<sstream>

using namespace std;

void add_matrix(int row1,int row2,int col1,int col2,double m1[30][30],double m2[30][30],double m3[30][30]);

[Code] .....

This program is suppose to read a matrix file , and the first getline is suppose to get the file header but it appears that 'line' doesn't take in any value other than empty thus causing all the problem , I tried to put cin.getline() in front of it to take away the /n created by the cin before it , but it doesn't work . When I debug the program when the arrow points to the string line , this error appears

line<Error reading characters of string.>std::basic_string<char,std::char_traits<char>,std::allocator<char> >

I tried to initialize string line=NULL too , doesn't work either.

View 1 Replies View Related

C++ :: Reading A File And Storing It In A String

Feb 7, 2013

I know how to do this in c++ with fstream and std::string and getline and so on and so forth. Im writing my code solely in c however. I can't get g++ installed so figured it was a good excuse to learn c instead of using the equivalent c++ abstracts.

My problem is, I'm making a game in c that I have made in c++ but have ran into an issue with my map. I want to read in my map from a file which just looks like this:
Name of Town
* * * * * * *
* * * * * * *
* * * * * * *
etc...

so i tried using fscanf to first read in the name of the town (stored in a char*) then read in the characters (in this case '*')(not including white spaces becuase i can just print those) into another char*. what is the better way to do this?

View 16 Replies View Related







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