C :: Read Characters From User Input And Construct A String

Mar 13, 2013

how to read characters from user and construct a sting and then extract part of it using substring?

View 2 Replies


ADVERTISEMENT

C++ :: Gather Input From User And Encrypt / Decrypt Those Characters?

Jan 5, 2015

I have got to create a program that will gather input from the user and then encrypt & decrypt those characters.

I'm not very confident at coding so I'm sure many parts of my code are written poorly and not following the best practice so I have written a simple version of an algorithm where the program simply adds/subtracts a value of 2 to/from the ASCII values but I have discovered the use of the rand() and srand functions but I'm unsure how to go about using them within both my encrypt and decrypt function as a single value (static variable?).

Here is my code in its entirety at the moment.

#include <iostream >
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
char getMenuSelection (char m);
void encrypt (char key[]);
void decrypt (char code[]);

[code]....

This code currently doesn't execute due to ' undefined reference to 'encrypt(char*) '

Question

I am asking how to generate the random number and incorporate this into my encrypt and decrypt functions.

1. Would the use of a static or global variable make this work as is?

2. Would I need to create separate class files for both functions?

View 2 Replies View Related

C++ :: Prompt User For Two Characters - Output Movies That Begin With Input

Nov 24, 2014

I have trouble printing out the movies starting with inputing only two letters.

#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;

const int NUM_MOVIES = 116792;
struct Movie {

[Code] ....

View 1 Replies View Related

C :: Comparing Of Characters In Given String From Input String?

Feb 7, 2013

I am stuck in this program, Be given a string of chars, where each single char belongs to the following alphabet: a..zA..Z0..9 (So, in the string there are only lowercases, uppercases and digits. No blank, no comma, ...). For every char of the given alphabet, count how many times in the string

1-- the char belong to a sequence of identical chars whose length is at least three (i.e.: in the string cc74uyrpfccc348fhsjcccc3848djccccc484jd for three times the character 'c' satisfies this condition)

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>

[Code]...

2-what is the longest substring of characters strictly rising interm of ASCII code(the following is greater (>) of the previous)

3- what is the longest substring of successive characters interm of given string rannge (i.e.: fhkjshdfruytyzABCDEfglsj => 7)

View 1 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C++ :: Read String Of Characters And Write With Punctuation Removed

Oct 13, 2014

Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.

This is how i did it:

string x("#punctuation!?=");
cout << x << endl;
for(unsigned i = 0; i < x.size(); ++i) {
if(ispunct(x[i]))
x[i] = ' ';
cout << x << endl;

I am just not sure if thats how they want you to do it because it doesn't remove the punctuations it just replaces them with a space.

View 3 Replies View Related

C/C++ :: Tic Tac Toe - Program Not Stop To Read In User Input

Jan 18, 2014

It's a tic-tac-toe program. I haven't finished doing everything I need to for the project, I'm just trying to get certain parts working as I go.

Anyway, my problem: The program will print the board and ask the first player which square they want to mark. Then it will print the updated board, print the question for the second player to input their square choice but not actually stop to let the user enter anything. Instead it prints the board again and then prints the question for player one again -- this time stopping to let them type in their choice.

Here's my code:

#include <stdio.h>
// Function prototypes
void printBoard(char board[3][3]);
int main() {
int quit = 0;
// Loop so game continues until player quits

[Code] .....

And it looks like this when I run it, as an example:

-------------
| 1 | 2 | 3 |
-------------
| 4 | 5 | 6 |
-------------
| 7 | 8 | 9 |
-------------

Player 'C' enter a square: 5

-------------
| 1 | 2 | 3 |
-------------
| 4 | C | 6 |
-------------
| 7 | 8 | 9 |
-------------

Player 'U' enter a square:
-------------
| 1 | 2 | 3 |
-------------
| 4 | C | 6 |
-------------
| 7 | 8 | 9 |
-------------

Player 'C' enter a square:

View 11 Replies View Related

C++ :: Read In Lines From A File / Store In Variables Then Construct Instances Of Class

Aug 22, 2013

I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.

I'm getting this error :

"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"

#include<iostream>
#include<string>
#include<fstream>
void displayInfo();
using namespace std;
class Employee{

[Code] .....

View 1 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/C++ :: UDF To Prompt / Read And Validate User Input And Return A Value?

Aug 5, 2014

I'm having a problem with the two while statements in my UDF.

- 1. It will run both while loops twice...?

- 2. It now goes into a continuous loop.

- 3. When it did work, it would only return 1 value to the main()...?

#include <iostream> // for use of "cin" & "cout", endl...
#include <iomanip> // for formatting setw function
#include <cmath> // for the general math computations
#include <string> // for creating descriptive strings
#include <sstream> // used to convert a string to an integer
//user defined function
int userValue (int);

[code].....

View 1 Replies View Related

C++ :: Read User Input - Count And Display Vowels

Sep 26, 2012

I'm trying to code a program to read the user's input and have it:

-count vowels
-stop counting vowels after '.' or '?' (ie. abcdjwef is 1 a, 1 e; while fje.fwdfeiii is just 1 e)
-closes when ENTER is pressed after a '.' or '?' is found (ie. closes after 'abacds. ENTER' as well as 'as.fefsdf ENTER')
-display the number of vowels

Is there any way to do this with only 'cin >> userInput' and a while loop checking for punctuation?

View 1 Replies View Related

C :: Compare String User Input With A String In Binary

Jul 14, 2014

I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..

Code:

#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}

[code]....

View 1 Replies View Related

C++ :: List Of Objects - Read Information From Each Object To Compare To User Input Prompt

Apr 19, 2013

I have a list of objects that I need to read information from each object to compare to a user input prompt.

#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);

[Code] ....

View 1 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

C++ :: Read User Input To Determine Different Discounts By Number Of Units Sold - Errors In Program

Jun 23, 2014

it will not run and im not sure why. I have a couple of errors, but I'm not sure why.

Here is my code.

//Reads input from user to determine different discounts by number of units sold

#include <iostream>
#include <string>
using namespace std;

int main() {
//Declaration and Initialization of variables
int quantity;
double discount,price = 99.00,totalCost;

[Code] ....

View 1 Replies View Related

C++ :: Program That Will Allow A User To Input Their First Name Into A String

Feb 23, 2015

So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"

My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.

#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;

[code].....

View 7 Replies View Related

C++ :: Age Is Int Variable And Name Is A String - User Input

Jun 18, 2013

I have a problem that states: age is an int variable and name is a string.

What are the values of age and name after the following input statements execute.

cin << age;
getline(cin, name);

if the input is:

a. 23 Lance Grant

b. 23 Lance Grant

Ok I have been fooling around with this book all day. My instructer wants us to build the program instead of just saying

a = 23 Lance Grant

How to input B. I mean when I write the program I do not know how to ask for two lines for one input.

View 1 Replies View Related

C :: Read String From Input Then Determine Which Character Is The Largest

Jan 12, 2015

I'm very new to c programming and I have some background in C# and java. I am supposed to read a string from input then determine in that string, which character is the largest, i.e. I think b>e and e>z, e.t.c. If the string is empty I should return ''.

I haven't done any programming in C before and I don't know how to handle strings and characters in C.

View 2 Replies View Related

C++ :: Capitalize Every Other Word In A User Input String

Nov 14, 2014

I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.

My logic is as follows:

1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).

My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..

I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..

Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Counting Vowels In User Input String

Feb 11, 2013

I need to write a program using at least one while loop to count and display the amount of vowels in a user input string. This is what I have so far.

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int acounter(0); // Create counters for each vowel

[Code] ....

View 2 Replies View Related

C++ :: Inserting User-input String To Array

Nov 8, 2014

I'm trying to code the program that will store item data.And I'm having problems to receive user-input string to array.

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iomanip>
using namespace std;

[code].....

View 6 Replies View Related

C++ :: Storing Information In String Without User Input?

Oct 9, 2014

Is it possible to store information in a string without user input? If so, what code would I use for it?

View 2 Replies View Related

C++ :: String Array - Sorting User Input

Oct 25, 2013

I have been reading up on arrays and string array. I created a string string text[0] and it is defined by user input. I am trying to sort the input. I want Michael to read Macehil.

When I wasn't using an array and just a string I did this:

return sort(text.begin(), text.end()); a

And it worked fine. Do I need to change my string into a char? If so, would I static cast that?

View 9 Replies View Related

C++ :: Converting User Input Int To String Output?

Apr 22, 2014

I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.

Code below:

#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
int convet(){
cout<<"Enter a number to convert to string "; cin>>num;

[code]....

View 2 Replies View Related

C/C++ :: Remove Vowels From User Input String

Aug 13, 2013

how to remove the vowels from the user input.?

View 4 Replies View Related

C :: Program That Allow User To Input String Then Scans The File

Sep 21, 2014

This program will allow the user to input string then scans the file if it contains the same string given by the user. But i always get "MATCHED" even if i enter random string. I tried and tried to place the if statement in different positions but i dont get my expected output.

Code:
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<string.h>
int main() {
int found;

[Code] ....

View 6 Replies View Related







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