C++ :: Function To Change Char Array String To Lower Case
Feb 17, 2014
This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). correct this function so it converts string to lower case and doesn't get errors.
#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
void ToLower(char s[]);
int main(){
string y_n;
How can I write program that can convert an input string into a form that only the first letter of the string is a capital letter and the rest is lower-case?
error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|. error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|. error expected '{' at end of input|.
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
I have been assigned the following task and I am having difficulty in getting it to compile. The compiler is stopping at line 27 but I don't no what the error is.
The task is as follows:
Write two functions with the following function prototypes:
int my string len(char str[]) void my string cat(char dest[], char src[], int dest size)
Both functions should take zero-terminated strings as input. The first function should return the length of the string to the calling function. The second function should take a source and a destination string and the total size of the array pointed to by dest. It should then concatenated the source string onto the end of the destination string, if and only if the destination string has the capacity to store both strings. If the destination string does not have the capacity it should not alter either, print and error, and return to the calling function. Demonstrate the use both the above functions by using them in a program in which you initialise two character arrays with two strings, print out their length, print out the combined length, and print out the combined string
And this is my code so far:
/* A program to demonstrate string concatenation */
#include <iostream> #include <string.h> using namespace std; int my_string_len(char str[]){ // function to calculate length of a chracter array int len = 0;
I am trying to understand why i keep getting errors in my code. The errors are after the string is converted in my console window. I have to allocate and delete memory via dynamic array to do the problem.
#include<iostream> #include<string> #include<cctype> using namespace std; int main() { string sentence; int size;
[code]....
I just want to know why the extra characters are at the end of my conversion and how to make them stop.
I am building a tamagotchi like application/game. As for the leveling up and changing of character I am using a char value so that the icon can change as the character progresses.
Due to the fact that the value for level is changing I need it to also change for what is being used for the case statements
I know I cant use variables in case statements because I have tried every way I can think of.
The code is
switch(Area[y][x]) { case '*': Area[y][x] = Level; break; case 1: { CODE } }
Where I have the case 1 I need it to change as level increases (as level is starting at 1)
I can get the first letter to change if there is only one word. But if there are two words it wont change and display the second word's first letter and I'm not sure why.
I want to create 2 functions to (1) convert a passed string into proper case (capitalize the first alpha character of a string and every alpha character that follows a non-alpha character); (2) sort the array of names (after it has been converted to proper case).
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox. char selectedValue[256]; memset(selectedValue, NULL, 256); SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue); // Convert to string. string val(selectedValue);
use 2D array in function and change the array values. I do not know if I can use array by calling from a function. I have 6 row 6 column array, I used it inside a function and for the another function I just need to change 4. row 4. column and I do not want to type array to just change one part. I do not know if there is another way or not
#include <stdio.h> void define (int integer, int IntArr[0], int *IntP); int main(void) {int integer = 0, IntArr[1] = {0}, IntP = 0; define(integer, IntArr, &IntP);
[Code]...
Why does the integer with array change after passing trough the function and the normal integer doesn't? (I know why the normal one doesn't, but I dont get the array one)
If we are using strcpy() for copying the string. As we are passing pointers to it It will copy the string & no need to return the string .This function will finely work with return type as void then why Ritchie has used it as char* strcpy()?
In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.
ReadNew function reads the file....check to see if it exist
CreateNew function creates a new file.
In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.
Code:
//Create a file, append to it, and read it. #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> using namespace std; char filename[256]; string n; string filelist; void CreateNew(ofstream & FileNew);
I have a text file with state names, and state abbreviations, thusly:
ALASKA AK ARKANSAS AR ..and so on.
I have to load the abbreviations ONLY from the file into an array of char[ - (already done and tested).
I have to get a 2 char abbreviation as a string,then test it against the state array to make sure it is a valid abbreviation. As it stands, my test is never finding an invalid abbreviation..
Here is where I get the input:
void getState() { char state[10]; getString("Please enter the state as a 2 char abbreviation:",state,10); printf("State Entered:%s", state); validState(state);
How do I convert a string of unknown length to a char array? I am reading strings from a file and checking if the string is a Palindrome or not. I think my palindrome function is correct, but do I do something like char [] array = string.length(); ??