C/C++ :: How To Ignore Case Sensitive While Comparing Each Character

Sep 26, 2014

The following Program ask a user to input a sentence. Program alphabetically sort individual character for each word.

My problem is, how do I ignore case sensitive if a user enters a uppercase letter. I try using stricmp but ran into some errors.

Below code:

#include <iostream>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
void bubblesort(char a[]);
int main() {
char sent[50];

[Code] ....

Current output:
input: today is a great day
output: adoty is a aegrt ady

Using Uppercase:
input: Today is a Great Day
output: Tadoy is a Gaert Day

What I want:
input: Today is a Great Day
output: adoTy is a aeGrt aDy

View 6 Replies


ADVERTISEMENT

Visual C++ :: Program To Reverse Sentence - Case Sensitive

May 31, 2014

I have to write a program to reverse a sentence like

cat
tac

but my program is case sensitive. Like if i enter sentence it gives me ecntenes(which is wrong). How to make it non case-sensitive using vectors? (I cannot use #algorithims)

// BackWardsSentence.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);

[Code] .....

View 2 Replies View Related

C++ :: How To Search Form Insensitive To Case Sensitive - File Handling

May 23, 2014

How to search form insensitive to case sensitive? I'm trying to emulate the behavior of the function "grep" in Unix.

#include <iostream>
#include <fstream>
#include<string>
#include<vector>
#include <ctype.h>
using namespace std;
int main(int argc, char** argv) {

[Code] .....

View 3 Replies View Related

Visual C++ :: Reverse Sentence - How To Make Program Non Case-sensitive Using Vectors

May 25, 2014

I had been tasked to create a program that reverses a word i.e.

cat
tac

How to make my program non case-sensitive using vectors?

Code:
// BackWardsSentence.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);
string BackWords1 (string sentence);

[Code] .....

View 2 Replies View Related

C++ :: How Is A Program Written To Ignore Case Sensitivity When Dealing With Input

Nov 9, 2014

I've written a simple program, which asks the user to respond to a YES or NO question using the character Y/y for YES and the character N/n for NO. The foundation of this program is based around several IF statements implemented to aid in finding the ASCII value of the character entered before invoking the corresponding cout statement that informs the user which character they entered. My Question: How should a program be written to deal with ignoring case sensitivity in regards to the users' input?

Here is my amateurish attempt,

Code:
#include <iostream>
using namespace std;
int main()

[Code] .....

The following are IF statements written for the program to determine whether the user answered YES or NO. The program then performs the cout statement that contains the corresponding character to the ASCII value found.

*/
if(user_input == 121 || user_input == 89)
{
if(user_input == 121)
{
cout << "

[code]......

View 2 Replies View Related

C :: Comparing Character To A Number

May 5, 2013

I created a function to check whether the first character of a string is a number or not by comparing it to every base 10 digit using a for loop. If it is, the string is valid, if it is not, the string is not valid

Code:
//ensure the first character is not a number
int ValidFirstChar(char FirstChar) {
int IsChar = TRUE, DigitCount = 0; /*boolean value indicating whether the first character is a number or not.*/

//check through all base 10 digits
for (DigitCount = 0; DigitCount <= 9; DigitCount++) {
if ((int)FirstChar == DigitCount)

[Code] ....

I have checked for the case where the first character is a number but it is displaying the error message for it. I have tried typecasting the char variable but that has not worked.

View 2 Replies View Related

C :: Switch Case Character Scanf (also Includes Arrays)

Nov 10, 2014

I'm trying to write a code that is read character user 'e' or ' ' space also numbers I mean a number 'e' or space 'e' a number 'e' or space so forth.But i get absurd numbers. The program shows me the added number. If '
' entered the taking numbers will stop(scanf will stop).

Example input:

e 1 8 7 2 3 6
or e 1 e 8 e 7 e 2 e 3 e 6

Code: #include <stdio.h>
#define MAX 10
void addq ( int *, int, int *, int * ) ;
void test();

[Code]....

View 2 Replies View Related

C :: Comparing Part Of Character Array With Scanned Input

Feb 25, 2013

I want to compare the part of the character array with the scanned input. I've initialized the character array (colourCompare).

What I want to do is, if the input colour matches up with one of the elements in the colourCompare array, it will then read the next value(I did not include "read the next value part"). If the input does not match up, then it goes back to the scanning part.

Code:

char colourCompare [12][6] = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Gray","White","Gold","Silver"};
float resistanceCal() {

[Code]....

View 14 Replies View Related

C++ :: Modify Contents Of 1D Character Array - Converting To Upper Case

Feb 10, 2015

I am unsure how to write a function which modifies the content of the 1D character array and puts all of the letter it contains into uppercase. the following are the letters which i am trying to convert.

char text[MAX+1] = {'T', 'e', 's', 't', 'e', 'r', EOT};

The output to this should look like T E S T E R EOT

View 2 Replies View Related

C :: How To Get Upper Case And Lower Case Equal

Feb 18, 2015

I just dont know how to get my upper case and lower case equal...heres the program: Write a program to calculate utility cost for ACME UTILITY COMPANY. The company has 3 types of customers (R) residential, (C) Commercial and (G) government. Customers are billed based on the number of kilowatts used and they type of customer they are (R,C,or G).

Residential cusstomers are charged 0.25 cents per kilowatt hour for the first 500kw used, and 0.35 cent per kwh for all kw used over 500.Commercial customers are charged 0.22 cents per kilowatt hour for the first 999kw used, 0.29 cents per kwh for all kw used over 999 kw up to 1999 and 0.45 cents per kwh for all kilowatts used greater than 1999. Commercial customers that use over 2000 kw are charged a special surcharge of 100.0 in addition to the regular charges.

Government customers are charged 0.34 cents for the first 1500 kwh used(<=1500). 0.30 cent for the next 1000 kwh(1501-2500) and 0.25 cents for all kwh used over (>=2501)

in addition residential customer are charged .5% tax on the cost utilities while Commercial customers are 5% tax on the cost of utilities not including the special surcharge Government customers are not charged a tax

Code:

#include <stdio.h>
#include <math.h>
int main(void)
{
int R;
int ct;
int kwh;
int taxes;
int surcharge;
int charge
}

[code].....

the program should quit with Q and calculate the amount owed, utility charge, and surcharge

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

C/C++ :: How To Ignore Certain Characters In A String

Sep 18, 2014

I am trying to cout just the first 5 characters the user enters into a string. I'm not sure how I can discard or not show the rest of the characters they try to enter after 5.

#include <iostream>
#include <string>
using namespace std;
int main() {
string random;
cout << "Enter any word." << endl;
cin >> random;
cout << random; //want to ignore everything after first 5 characters entered.
return 0;
}

View 1 Replies View Related

C++ :: Ignore Code When Compiling?

Sep 7, 2012

In a rather large codebase, there is a set of recurring calls to a couple vararg functions (mainly for logging)

Code: logthis(foo, bar(), somefunction(parameter1,parameter2), somethingelse);

The number of parameters to this function is variable It has all types of variables, function calls, etc.

The code has thousands of these lines

There is now a need for a special version of the compile that will remove a lot of the code, among others is the logging.

Can I somehow #define the "logthis" name into something that'll remove all actual calls to the code. including the actual parameters/expressions to the call.

I can't afford to add #ifdef/#endif around each of the calls because there are too many of them, and because that'll cause some undisired side effects in our code conformance tests.

Code: #define logthis __noop

comes close, that removes the call, but it still causes the compiler to evaluate and validate all the parameters to the logthis function, which doesn't work because in this case, removing the logging headers also removes other members of the class that get used as part of the parameters to logthis()

if I could define logthis into // resulting in all the rest of the line being comments, but that doesn't work.

Preferably I'd like something to be portable, but I'll take a solution that only works on visual studio as well.

View 6 Replies View Related

C :: Ignore Negative Numbers In Array

Feb 15, 2014

So i have this program that takes in user input and stores them into an array and then prints them, removes duplicates, and sorts in ascending order. The user can also stop by inputting a sentinel value (in this case -1). But i am also supposed to ignore any negative value besides -1. When i input any other negative value into the program it messes up. How would i go about ignoring the negative values?

Code:
#include<stdio.h>
int main()
{
int input, nums[20], i, j, k, temp, count=0, count2=0;
for(i=0;i<20;i++)

[Code] .....

View 8 Replies View Related

C++ :: GCC - How To Fully Ignore Warnings From Libraries

Dec 30, 2013

I know I can use -isystem path to mark a path as containing system headers which shouldn't be included when generating warnings, and this works, but it doesn't work when the warnings are generated by instantiating templates from the library in my source code. Is there any way to ignore these template-instantiation-generated warnings too?

View 13 Replies View Related

C++ :: Thread Can't Ignore Void Datatype?

Mar 31, 2013

the compiler doesnt accept void functions used with threads (for the first time and all of sudden!?)

#include <cstdlib>
#include <thread>
#include <windows.h>

[Code]....

this is a sigment of my code. Compiler says that the error occurs in line 47 (marked by ***). Leaving out the braces makes it even worse.

View 3 Replies View Related

C/C++ :: Ignore Strings From Being Entered By User?

Oct 6, 2014

how I can ignore strings from being entered by the user. When the use enter's a string it always evaluates it as even. I though I might use a cin.ignore(); but I am unaware of how to use it.

#include <iostream>
using namespace std;
int main() {
cout << "Enter a number: ";
int num = 0;

[Code] ....

View 2 Replies View Related

C++ :: Read The Numbers In A File While Ignore Text?

Sep 20, 2013

I want to write a c++ code, which will read in a file like this:

A: 10
B: 20
C: 30

while in the code, I would need the value of A B C, how can I let the cin ignore the labels like A:?

of course, I can write a file as

10
20
30
.
.
.

and use cin>>A>>B>>C; to read in those

but in this way, when the number of values increase, it is really hard to remember who is who?

View 5 Replies View Related

C++ :: Multi-character Character Constant Error Message?

Sep 14, 2014

I keep getting this warning message and I do not know how to fix it. Is it because I'm using char to instead of strings to replace all 't' with 'lp'?

#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
char * scanf(char * a) {

[code]....

View 6 Replies View Related

C++ :: Reading Data Character By Character From Text File

Jul 25, 2012

Double values are stored in text file. 23.5 36.8 34.2 ... My teacher told me to read them character by character and then make words, like i have to read "2" "3" "." "5" and now have to make it or treat it as word and then using atoi(). I have to convert it into double. but i dont know how to do this....

View 5 Replies View Related

C :: Read From Stdin (File) Character By Character

Nov 10, 2013

I have to optimize a code for below scenario. I am reading stdin (a file redirected to stdin) character by character. How many chars are going to come is not known. After every few chars there is a seaparator. e.g $ as below

rhhrkkj$hghjhdf$ddfkrjt

While reading, if the separator arrives I'm processing the string stored before that separator and then continue reading stdin in same fashion, till EOF. I am using getc(stdin) to read chars.

Using gprof I can see most of the program time is spent inside main() , for this reading logic. Rest of the program is just some insert and search operations. I am getting time of 0.01 secs at the moment, want to reduce further.

View 6 Replies View Related

C/C++ :: Read Input File Character By Character?

Aug 10, 2012

How do I write an a program that will read an input file character by character?

View 1 Replies View Related

C++ :: How To Read TXT File Character By Character

Oct 6, 2013

In my program, I'm supposed to read a text file (the name of which is given to me as a command line paramater, as long with an integer), and display the text in a specific format (each line can only be as long as the integer). However, I'm having trouble even reading the text file. I don't know the syntax. I'm only allowed to edit the function that does the formatting, and the code in that is

void typeset (int maxWidth, istream& documentIn)

I don't know how to 'read' the file, as most examples online are ifstream, or openFile or something like that. What I want to do is just read the first character of the file, and continuously keep reading characters until the end of the file.

View 10 Replies View Related

C/C++ :: Replacing Character In String With Another Character

Sep 13, 2014

So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:

In my implementation file

void NewString::ReplaceChar(const char& target,const char& entry)
{
this->replace(this->begin(),this->end(), target, entry);
};

Main program

#include "NewString.h"
using namespace ...;
int main()

[Code].....

Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.

I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:

bool NewString::operator ==(const char& target)const {
if(*this == target)
return true;

[Code]....

I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.

View 5 Replies View Related

C :: Assignment Of Element Of 2D Character Array To 1D Character Array

Jul 4, 2014

Can we do this :

Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];

View 3 Replies View Related

C++ :: Case Statement Not Working?

Mar 6, 2015

I have this case statement that is not performing as expected. For some reason ASE_OK and ASE_NotPresent both print out. Why is this? ASE_OK is a return value of 0 while ASE_NotPresent is -1.

Code: // Try to create the buffers and store it
switch (theAsioDriver->createBuffers(info, numChannels, bufferSize, callbacksInfo)) {
case ASE_OK:
std::cout << "ASE_OK";
input->bufferSize = output->bufferSize = bufferSize; // Buffer size is stored in both input and output
case ASE_NotPresent:
std::cout << "ASE_NotPresent";
errorMessage = "Could not find input or output devices.";
return NO_DEVICES_FOUND;

[code]....

View 3 Replies View Related







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