C :: Input A String And Get It Reversed
Sep 15, 2013
So I was trying to input a string and get it reversed. I came up with his code. It is supposed to work by first creating two strings, then I get the input of a string and then try to reverse it using a while loop. However the output each time is pure garbage, what exactly have I overlooked?
Code:
#include <stdio.h>#include<stdlib.h>
int
main (void) {
char z[255];
char y[255];
int x,r=0;
[Code] .....
View 2 Replies
ADVERTISEMENT
Feb 6, 2014
#include <stdio.h>
#include <string.h>
#define MAX 1000
main()
{
char text[MAX], c;
int i,s;
[Code]...
I need to edit the code here to make the input by the user show up reversed
puts("
Your reverse input is:");
for(i = length - 1; i >= 0; i--){
printf("%c",text[i]);
}
I know this is not right...
View 4 Replies
View Related
Mar 30, 2014
I need to reverse a word . For instance "Hello" after reversing will be "olleh" . It reverse first and last letter but its not reversing the rest of them
char arr[]="Hello";
int first=0;
int last=sizeof(arr-1);
int mid=sizeof(arr)/2;
[Code] ....
View 2 Replies
View Related
Jun 14, 2013
The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?
Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^
[Code] ....
Is it just my compiler?
View 5 Replies
View Related
Oct 19, 2014
Very new to programming, and I know that there must be another way on inputting a string into each array cells not by just inputting it one by one, but as a whole. My code at the meantime is: [URL]
View 1 Replies
View Related
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
May 29, 2014
I wrote a program that reads a list from a file and stores it in a string type vector. Now, I want the user to input a word so that the program can search the vector to see if that word already exists. I have used every possible way of reading input from the console and storing it in order to compare with the vector but it never results in a match. When I print the input string and the vector string they are exactly the same thing (or at least print to the console as if they were). I've tried using getline; using cin direct to a string var; using cin to a char array and then casting to string using string str(arr); I even added a newline at the end just in case and STILL I cannot get a match.
vector <string> currentSet; //read a list in from a file and has 9 items in it
cin.ignore();
string line;
getline(cin, line);
if(line == vector[0]){//if printed to console line is HEAT and vector[0] is HEAT
cout<<"match"<<endl;
}
View 3 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
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
Jun 26, 2014
/*assume array is already initialized and declared and is of array type string.*/
int i = 2;
int j = 1;
string newvalue;
cout<<"Current value at array[i][j] is "<<array[i][j]<<endl;
cout<<"Enter new value "<<endl;
cin>>newvalue;
array[i][j]= newvalue; //PROBLEM IS IN THIS LINE.
cout<<endl;
cout<<array[i][j]<<endl;
I'm having lots of trouble with storing a cin string text into a string array. It just seem that after I cin newvalue, the program crashes. Is this way of storing it considered illegal? I'm just a beginner with 5 months of coding experience in C++.
View 1 Replies
View Related
Oct 20, 2014
i wanna put an integer into a string for example:
Code:
string name;
int num=8;
name= "George"
//
I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();
View 7 Replies
View Related
Apr 15, 2014
I have an assignment where I need to write a hangman program. I have almost all of it done, however, I am having trouble getting my head around checking to see if the letter guess is in the string and how many times. This is my code, the section in comments is where I am having the trouble.
Code:
#include <stdio.h>
#include <ctype.h>
int main() {
char word[10]; //secret word array
char wguess[10]; //word guess array
char lguess; //letter guess
int i;
[Code] .....
View 4 Replies
View Related
May 24, 2014
I'm having trouble printing the text in between separators like commas, periods, and at signs. I'm following Jumping into C++ Chapter 19 Practice Problem 2.
This is what I have so far:
Code:
#include <iostream>#include <string>
usingnamespacestd;
int findNeedle (char separator, string inputLine) {
int needleAppearences = 0;
[Code] ....
And this was my test run output:
Enter the contact info. one, two, three, ,? , one two, th three, Program ended with exit code: 0
View 4 Replies
View Related
Aug 14, 2013
Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.
Sample Run 1:
Input -> A111B222C
output -> 9
Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62
View 1 Replies
View Related
Sep 16, 2013
I'm extremely rusty at C but is this the best way to store an input string into a char*?
Code:
int length = 100; //initial size Code: char * name = malloc(length * sizeof(char)); //allocate mem for 100 chars
int count = 0; //to keep track of how many chars have been used
char c; // to store the current char
while((c = getchar()) != '
'){ //keep reading until a newline
if(count >= length)
name = realloc(name, (length += 10) * sizeof(char)); //add room for 10 more chars
name[count++] = c
}
Is this a good way and what could be better?
View 2 Replies
View Related
Mar 6, 2015
I'm doing error checks in C and I'd like to know how to restrict the input of a string to 2 letters and if it is exceeded, i'd like to loop and ask for the code to be re-entered.
Code:
for (i = 0; i < code7; i++)
{
printf("Enter number of items: ");
scanf("%d", &item_qty[i]);
[Code].....
View 2 Replies
View Related
Jul 23, 2013
I need to ask the user to input a number, and then put the number in a string array. so for example if the size of the number was 4: example 1200
i would make him put the number like that
for (i1=0; i1 < 4; i1++)
cin >> Num1[i1];
where Num1[] is a char array type. yes and it works.
But my question is what if I do not know how many numbers will the user put, how do i extract the size of the total characters existing in a number?
View 5 Replies
View Related
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
Nov 22, 2013
I'd like to input a file and store the contents of the file in a string.
Here is my code:
std::string inputFile();
int main() {
std::string fileContents = inputFile();
} std::string inputFile()
[Code] ....
It works fine if the file name and path is input correctly.
But, if the file name or path is entered incorrectly, the recursive call to inputFile is executed, and the user is given another opportunity to enter the file. Then, if the file name is entered correctly an error is thrown in Visual Studio 2013:
"Unhandled exception at 0x77F7A9E8 (msvcr120d.dll) in Assignment4.exe: 0xC0000005: Access violation reading location 0xCCCCCCC0."
How could this be done better?
View 1 Replies
View Related
Sep 15, 2013
I'm trying to write a simple program that will prompt for a string typed in by keyboard and save it to a file. I've tried lots of variations and this is just the latest version.
//Prompt for a string input by keyboard and save it to a file
#include<iostream>
#include<fstream>
#include <string
using namespace std;
[Code] .....
View 2 Replies
View Related
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
Jul 2, 2013
Im having trouble with the while loop, this program should ask the user for their name, if incorrect it should send an error msg and ask for input again...after the correct name is entered the program should prompt the user to enter a password, again if incorrect it should send an error msg and ask for input again.
the code below does what it should when asking for a name..HOWEVER it does not allow the user to enter a password and instead jumps straight to the error msg..
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main() {
// Variables
string username;
string password;
[Code] .....
After the correct name is entered, the program displays this:
"Welcome, Sadia Rajput."
"To continue, enter your password: That is incorrect, enter password: "
I would prefer to do this using the while loops and not bool statements
View 1 Replies
View Related
Feb 8, 2015
I am writing a program that asks the user for their gender. I know that atoi converts arrays into integers, but I need the input from the user in the form of F or M into a char, and return it to the main function to be displayed at the end of the program.
string Employee::getgender(char gen)
{
cout << "Please enter your Gender: " << endl;
//atoi function would go here, what for char?
getline(cin,gen)
return gen;
}
View 1 Replies
View Related
Nov 3, 2014
Explain this program to reverse an input string:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main() {
void reverse(void);
clrscr();
reverse();
[Code] ....
Do not assume i know about getchar and putchar.
View 2 Replies
View Related
May 28, 2013
I want to input a string in C with white spaces in between. I have tried %[^/n]*c, and fgets, but both do not work.
View 7 Replies
View Related
May 16, 2012
I'm get input from the user and then storing it in "s " and then trying make tokens, but it is not working, and after making tokens I'm counting them. Here is My Code
Code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
string s;
[Code] ....
Here is my Output
Enter text:
Entered Text is: This is String
token 1: This
token 2: is
token 3: String
token 4:
Number of tokens: 3
The problem is that i want to store the first two strings "This" and "is" into two variables and how to remove token 4: which is unnecessary .
View 5 Replies
View Related