C++ :: Read A String From Keyboard

Mar 27, 2013

char name[10];To read a string from keyboard.

what should i use :

this : cin>>name[10];
or
this : cin>>*name;

View 3 Replies


ADVERTISEMENT

C :: Possible To Read Text Form Keyboard Using Read Function?

Dec 8, 2013

Is possible read text form keyboard using read() function? or which is best way in ansi creplace input command form basic language. for numbers and text...

View 3 Replies View Related

C++ :: Read Three Numbers From Keyboard And Find The Average

Jan 17, 2013

1): write program to c++ to read three numbers from keyboard and find the average of the three numbers?

2): write program c++ to read two numbers from keyboard and swap between numbers like x=4; y=6; the result x=6; y=4;?

I think that int can do that job. but im not sure.

3): must be the result of positive example: (x+(-y)=z)?

with abs ?

4): values for each of : X= ;y= ;z= ;

View 7 Replies View Related

C++ :: Read Float Numbers From Keyboard And Store Them Into Array Of 10 Elements

Jan 10, 2013

I have to complete a project that i want to read float numbers from keyboard and store them into an array of 10 elements.! Every time that a number stored into array i want to compare with previous one if they have +-10 difference .. I want to keep only 10 elements into my array so every time that i give value a[0] replace a[1], a[1] replace a[2],a[2] replace a[3]. . . .and a[10] deleted.. So when all elements of the array are similar with +-10 values print out the array.!

View 1 Replies View Related

C/C++ :: Program That Read A Number From Keyboard And Print Separated Digits To Screen

Feb 18, 2015

Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.

For example, if the number is 2339 the program should print

9 *********
3 ***
3 ***
2 **

So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!

My code so far:

int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d

[Code]...

View 4 Replies View Related

C :: Read A String With & Symbol

Nov 26, 2013

Why is this correct?

Code:
char str[10];
scanf("%s",&str);

I knew that when we have strings we should not use & in scanf()...

View 1 Replies View Related

C++ :: Read Integer To A String?

Oct 15, 2013

How do I read integers to a string and store then into a vector array?

I need to add two input digits i.e. "1234567878887777" and "123344543543543"

View 8 Replies View Related

C++ :: Read String From The File?

Sep 23, 2014

I have an example text file that contains:

***xyz text********
***********<td>temperatura: </td><td class="data">19.8 °C</td>
***xyz text********
***********

How can i extract the number 19.8 from that file?

View 3 Replies View Related

C :: How To Read String From Binary Files

Sep 6, 2013

I have a structure stored in a binary file, now I want to read each string from it (or line), can I do that using fgets?

View 12 Replies View Related

C++ :: Read String In File And Add Count

Jul 22, 2013

I'm looking for a program to read a file to look for strings and add a count.

kill.log in the same folder as program

player1 was killed by player2
player2 was killed by player1

4 strings
player1 was for "d1" add count
player2 was for "d2" add count
by player1 for "k1" add count
by player2 for "k2" add count

cout << Player 1 kills: << k1 << deaths << d1;
cout << Player 2 kills: << k2 << deaths << d2;

add up each time.

View 7 Replies View Related

C++ :: How To Read A String And Then Compare It To A Word

Mar 5, 2014

I'm trying to read a string and then compare it to a word.

My code:

char* cmd = "start";
std::cin >> cmd;
if (strcmp (cmd, "eval"))
eval ();

When the program gets to the cin part, it breaks.

View 4 Replies View Related

C/C++ :: Can't Read In String From Text File

Feb 17, 2014

I'm trying to make a program that will read in names and grades from a text file and print them in the console. However whenever I try to use the OpenFile.get function I get an error saying that there is "no instance of overloaded function"

getting this error resolved before I can.

my code so far (I know it's missing a lot, but that's not what I'm worried about right now.)

#include <fstream>
#include <iostream>
#include <string>

[Code]....

View 7 Replies View Related

C++ :: Read A String Of Unknown Length From Stdin

Oct 10, 2014

I want to read a string of unknown length from stdin. I tried to follow the approach from this link. URL....My code is like this:

#include <iostream>
#include <string>
using namespace std;
int n;
cin >> n;
cout << "The value of n is " << n << endl;
}

[code]......

What I have noticed is that if I take integer input from cin (cin >> n;) in the above code before getline, the control does not stop on getline to take str as input from the console. If I don't do (cin >> n) before getline then the control stops on getline and takes the string as input.What is the best way to read from console multiple strings of unknown length in combination with the integers?

View 5 Replies View Related

C++ :: How To Read All Content From A Text File Into A String

Sep 24, 2013

I'm trying to read all content from a text file into a string. This is the code I'm using for it (I know there are other, maybe better ways to do it but I'd like to stick to this for now):

char* buffer;
std::string data;
FILE* fp = fopen("textfile.txt", "rb");
if (!fp) {
printf("Can't open file");

[Code] ....

So my problem is that I get an exception when I try to free the memory -> 0xC0000005: Access violation reading location 0x51366199

I even get the exception when I try to free it immediately after calloc() but why this is.

And if I use buffer = (char*)malloc(lSize); I don't get any exceptions.

So, why this fails and what I'm doing wrong.

View 14 Replies View Related

C++ :: Read In String From File And Convert It Into Enum?

Dec 2, 2013

I defined

enum boundaryType_t {inside, inlet, outlet, wall, periodic};

now I have file written like this:

inside outlet

I want my program read the file and when encounter any enum type, instead of treating it as a string, I want the program store it in memory as a enum value.

How can I do that?

string s;
ifs>>s;
s // how to convert it to enum???

View 5 Replies View Related

C/C++ :: Read In String With Multiple Words And Numbers?

Jul 23, 2014

I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.

cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;

View 1 Replies View Related

C Sharp :: How To Read And Split File As String

Apr 16, 2013

how to do this in C#. Need to connect to Oracle db, take a file from directory then read every line of the file. Lines are like this:

123234847656|8800359898818177|A|20130401 14:51:42|
123234847212||D|20130401 14:52:08|
123234847212||M|20130401 14:55:38|

Then will split as string on every '|' char and according to this flag |A|, |D| or |M| I will add/delete/modify information inside. I have trouble with this part with the connection and read/split file and check for the flag A, D or M.

View 2 Replies View Related

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 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++ :: 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++ :: Using Fgets To Read In A String - No Conversion Function Error

May 27, 2013

I am trying to use fgets to read in a string, but keep getting a "no conversion function from std::string to char" error.

View 2 Replies View Related

C++ :: Read Phone Number Into Array And Can't Use String Data Type

Jan 13, 2013

I have an assignment where I need to read in a phone number into any array and I can't use the string data type. Assuming I need to use the getline function, how do I do this? I'm guessing it's with the cstring or .c_str() functions? I don't know.

View 4 Replies View Related

C/C++ :: Read From File / Assign As String And Call Function As Argument

Oct 29, 2014

I try to use passing function as argument but I'm stuck. I have two questions: First, I try to call uppercase and open .txt in tfm Second, How can I read characters from in.txt as string and assign to char content[] ?

#include <stdio.h>
void tfm( char str_filename[], void(*pf_convertion)( char content[]));
void uppercase(char content[]); //converts all letters to uppercase
int main(){
puts("-------------------------------");
printf("tfm:
");
tfm("in.txt", uppercase);

[Code] ....

View 2 Replies View Related

C :: Capturing Keystroke From Keyboard

Jun 11, 2013

I want to intercept key to my program even if it is non active. I'am working on linux machine(ubuntu)..what should i use to do this?

View 6 Replies View Related

C :: Program Respond To Keyboard Hit?

Mar 6, 2015

What C command responds to a keyboard hit? I want to exit in an orderly manner from a continuous loop when a key is pressed.

View 5 Replies View Related

C :: How To Ignore All Key Presses On Keyboard Except 1-5

May 7, 2014

Here is the function I am trying to modify...

Code:
void DisplayAdminMenu() {
char ch;
system("cls");
printf("Admin Menu");

[Code] ......

Error! Must enter a number between 1 and 5

View 6 Replies View Related







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