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


ADVERTISEMENT

C/C++ :: Converting String To Upper Case Via Dynamic Array?

May 21, 2014

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.

View 3 Replies View Related

C :: Converting Two Strings To Upper And Lower Case Using Function

Dec 6, 2014

My code so far

Code:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

[Code]....

I keep getting these 3 errors :

error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|.
error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|.
error expected '{' at end of input|.

View 4 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 :: Segmentation Faults When Trying To Modify A Character Array

Apr 27, 2013

I've initialized a character array in my main, and passed it onto one of my functions convertToPostfix(char infix[], char postfix[]). It isn't a constant read only array (constant char*) ive explicitly initialized it to char postfix[] = "";

Code:

if ((nextChar > 47) && (nextChar < 58)){ //if its a digit
postfix[++postfixIndex] = nextChar;
while (infix[i + 1] > 47 && infix[i + 1] < 58){
nextChar = infix[++i];
postfix[++postfixIndex]=nextChar;//segmentation fault when assigning from infix to postfix**
}

View 3 Replies View Related

C++ :: Change First Letter Of Each Name To Upper Case?

Oct 2, 2013

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.

#include <iostream>
#include <iomanip>
#include <cstring>

[Code].....

View 3 Replies View Related

C :: Way To Check If Letter Is Upper Or Lower Case

Jul 7, 2014

can i do in this way to check if letter is upper case or lower case is it better to using casting or i can do without casting.

Code:

if(selectOption == (char)81){
selectOption = (char)113;
}

View 2 Replies View Related

C/C++ :: Upper Case Conversion And Digit Summing

Feb 23, 2015

Write a program that reads characters from the keyboard using the getch() function. All lower case letters will be converted to upper case and printed out to the display using the putchar() function. All uppercase letters will be printed using putchar(). All individual digits will be accumulated and the sum will be printed at the end of the program using printf(). You will write a function to return the upper case of the letter and a second function which receives the current sum and the character digit.

The convert digit function will convert the character digit to a decimal value and accumulate the digit to the sum returning the new sum. Only the letters will be printed out nothing else. The program will continue until the return is received at which time the sum of the digits will be printed on the next line. What was entered: a9 wF23’;/4i What the line actually shows: aA9wWFiI The sum of the digits is: 18

I dont understand why it expects more () in the functions....

View 11 Replies View Related

C++ :: String Find And Replace (Modified To Upper Case)

Feb 3, 2013

"C++ is a general-purpose programming language." I have to find the word "C++" and replace it with "Java" and then capitalize all letters.

#include <iostream>
#include <string>
using namespace std;
int main( ) {
string origin; //contains input string
string replace; //the string obtained by replacing "C++" with "Java"

[Code] ....

View 1 Replies View Related

C :: Transferring Contents Of One Character Array To Another Function

Feb 1, 2014

In the function *expandArrayList and *trimArrayList I need to allocate either more memory or less memory to the given array. Right now I am using malloc on a new array and then transferring the elements of the original array to the new array, freeing the original array, and then reassigning it to the new array so it's size and capacity are either bigger or smaller than the original. I feel like there has to be a simpler way to do this with either realloc or calloc, but I cant find sufficient information on either online. Would I be able to use either to make this easier and the code cleaner?

Also, these are character arrays that contain several character arrays inside them, so I was wondering what the best way to transfer the contents of one array to the other would be. I have gone between

Code:

//example
for (i=0; i<length; i++){
newarray[i] = oldarray[i];
}
and
Code: for (i=0; i<length; i++){
strcpy(newarray[i], oldarray[i]);
}

but I'm not sure which one (if either) should work.

The 'ArrayList.h' file that is included contains the structure ArrayList, as well as the function prototypes for the functions listed below.

Here is the structure in ArrayList.h:

Code:

#define DEFAULT_INIT_LEN 10
typedef struct ArrayList {
// We will store an array of strings (i.e., an array of char arrays)
char **array;

[Code] ....

Here is my code:

Code:

//included libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ArrayList.h"
//Create arraylist

[Code]....

View 3 Replies View Related

C/C++ :: How To Open A File And Store Contents Into Character Array

Jan 2, 2014

I am trying to store a large text file into an array so I can count the number of characters.

View 2 Replies View Related

C++ :: Simply Converting Character Array To A Short Int

Feb 14, 2013

Any function of simply converting character array to a short int?For example. char array[4]={'0','2','f','f'}; to short int 767?

View 3 Replies View Related

C :: Original Text File / Generate Another File With Text Content In Upper Case

Nov 29, 2014

Code software that, from an original text file, generate another file with the text content in upper case.For exemple:

entrence:

luke
tom
alex

outings:

LUKE
TOM
ALEX

My code so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}

[code]....

View 2 Replies View Related

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 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++ :: Converting Reference Address To Character String

Jun 15, 2014

I'm wanting to convert the reference address held by a pointer into a character string, combine the hexes into a single unsigned long int(using bitwise operators )so I can use the 32bits in conjunction with a separate algorithm to develop a more efficient, but less 'random', number, or should I say bit, generator that I'll be using in a Neural Network, with Genetic Algorithms used to modify the weights.

View 5 Replies View Related

C :: Find Closest Upper Value In Array For Any Input Int

Jul 29, 2013

I have this array (assume sorted) and i need to find out the closest upper value for any input int. Example:

Code:

/* bsearch example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* qsort, bsearch, NULL */

int compareints (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );

[Code] ....

So whenever i hit something that is not in the array i would like to know the closes upper value. So for 4 closest upper value is 5, then for 8 it is 12 , for 35 it is 44. how would one do this?

View 1 Replies View Related

C :: Printing Contents Of A File - Prints One Extra Character Not Present In The File

Feb 12, 2013

I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)

_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60

When printed out, the names are formatted as follows:

lastname, firstname: 90
lname, fname: 100
last, first: 60

However, when I print them out this is what I get:

lastname, firstname: 90
lname, fname: 100$
last, first: 60H

For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.

Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {

[Code]......

View 6 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 :: Modify Value Of Whole Array By Passing It To A Function - Invalid Lvalue Error

Sep 23, 2013

i want to modify value of whole array by passing it to a function and make each value of array multiplied by 3 ,return the value to main and print it using pointer.

error : invalid Lvalue is the error

Code:

#include<stdio.h>
main()
{
int i,arr[10];
for (i=0;i<=9;i++)
{
printf("Enter value of arr[%d] : ",i);
scanf("%d",&arr[i]);

[Code] ....

View 1 Replies View Related

C++ :: Enforcing That A Function Does Not Modify Dynamic Array Pointed To By Pointer

Aug 21, 2014

In case the question was not very clear. Say I have the following code:

int sum(int * x, size_t N){
int sx;
/* returns sum of elements in x */
return sx;

[Code] ....

I'm curious to know whether there is a way that ensures a function does not modify the memory pointed to by a pointer.

View 9 Replies View Related

C/C++ :: Printing The Contents Of The Array?

Feb 18, 2014

I am writing a code with C where I will give an integer and get the binary conversion of it.I tried to fill the binary digits into an integer array.But when I normally print it will give the proper output.But when I try to print the contents of the array it will not produce the proper result.

My code would be as follows.

#include <stdio.h>
#include <conio.h>
int main()

[Code]....

View 5 Replies View Related

C/C++ :: Reversing Array Contents

Feb 21, 2015

I'm trying to reverse 25 items that are in my array by using a For Loop and sending 2 of the numbers to a function at a time. The code I have right here, is not working at the moment, I cannot find the problem because i've been staring at my code for too long.

int farEnd = 24;
for (int i = 0; i < 24; i++){
Swap(intArray[i], intArray[farEnd]);
farEnd--;
}

Also here is the code in my function

void Swap(int num1, int num2){
int temp = 0;

temp = num1;
num1 = num2;
num2 = temp;
}

View 5 Replies View Related

C++ :: Display Contents Of Two-Dimensional Array

May 4, 2014

//Introductory20.cpp - displays the contents of a two-dimensional array, column by column and row by row

#include <iostream>
using namespace std;
int main() {
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}};

[Code] .....

I need modifying a program that should display the contents of the two- dimensional array, column by column and also row by row. I need to complete the program using a WHILE statement in the outer loops and a FOR statement in the nested loops.

View 1 Replies View Related

C++ :: Zero In List Contents And Multiset Contents

Apr 24, 2015

HTML Code:

So I insert values from a vector into a list and into a multiset, and I noticed zero is added to their contents! I had to do a whole lot of debugging to find out where the error was, how can i stop this thing? Code which generates such error...

infact i checked the content of vector ups to be sure that there was no zero in it, but after loading into list combi_t * head, it seems like there was a zero added and this is giving me errors when i call function master_roller...

Code:
void ins(combi_t * &testa, int &numero, int &num, int &no)
{ // if (ricerca(testa, numero) == 0)
//{
combi_t *temp = new combi_t;

temp->val0 = numero;
temp->val1 = num;
temp->val2 = no;
temp->nextPtr = 0;

[Code] ....

View 2 Replies View Related

C++ :: How To Load Contents Of Text File Into Array

May 12, 2013

So I am working on a FUSE filesystem and I currently have the need to load the contents of a text file into an array.

My array initialization looks like: char array[max_entries][PATH_MAX] = {NULL}

The reason I want to pass it by reference is that I want my function to return two values essentially. One a specific char* and the other an array like I initialized. My function proto type looks like:

char* load_meta(char* list[max_entries][PATH_MAX], char* path, int mode);

How I'm trying to call the function:

someChar = load_meta(&array, path_name, 1);

Within the function I try to edit the array by deferenceing it once, like this:

strcpy(*list[i], file_entry); // This seg faults

View 8 Replies View Related







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