C++ :: Adding String But It Return Some Integer Value
Jun 10, 2013string str = "sfsdfsd"
and i want to add like str[3]+str[4]
but it return some integer value
string str = "sfsdfsd"
and i want to add like str[3]+str[4]
but it return some integer value
In my program I'm trying to add 200 to the variable named "gold". I thought this would work, but I guess it's not:
int gold2=gold+200;
int gold=gold2;
I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:
OBJ 1:
2 3 4
OBJ 2:
1 4 -2
Addition:
OBJ 1 =
3 7 6
Subtraction:
OBJ 1 = 1 -1 6
But when I run and compile my program, this is what I get:
OBJ 1:
2 3 4
OBJ 2:
ADDING:
OBJ 1 =
4 6 8
Subtraction:
OBJ 1 =
Here is my current main.cpp:
Code:
#include <iostream>
#include "SafeArray.h"
using namespace std;
[Code].....
Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.
Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}
I wrote:
#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';
[Code] ....
0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?
So I have a simple calculator that does a few operations (+ - * / %) Pretty basic stuff
I declared int x, y for the numbers, char operation, and float result.
the code is based on switch(operation)
The program is running alright, but when I divide 8/7 it returns 1 as the result, I tried changing the x and y to float but that won't work because of the case '%'
I also tried making local float variables in the case'/' but it won't compile "E2126 Case bypasses initialization of a local variable"
How can I make the division work and return a float value?
The problem is how to return an array of integer from a function?
I'm writing a C program code to return an array of integers ( grades of students ) to the main function!
Write a function named maxValue that has three integer parameters. The function should compare the three values and return the highest value.
View 10 Replies View RelatedReturn the digit at the user specified index of an integer. If the integer has n digits and the index is NOT in the range 0 <=index <n return -1 Start the digit numbering at 0. Example, if user input is 4 (index) and the integer equals 123456790 the return value for the function is 5 (start index at 0) ; if user input is 40 (index) and the integer equals 123456790 the return value for the function is -1
#include <iostream>
#include <istream>
#include <cstdlib>
#include <cassert>
#include <string>
using namespace std;
int getIndex(int, int);
[Code] .....
I want to write a function which take an integer and return the number of digits in it i.e
int i = 123456
func(i) {
some code
}
output
the number of the digits are 6
I have a function that I want to exit gracefully when an "error" occurs in an input file. My function declaration is:
Code: BSTnode *buildTree(FILE *fp)
The few lines that are causing the problems are:
Code: if(regcomp(®ex, to_find, REG_EXTENDED | REG_NEWLINE) != 0) {
fprintf(stderr, "Failed to compile regex '%s'
", to_find);
return EXIT_FAILURE;
}
I know that if I just use "return" by itself the warning goes away but fails to exit when the error occurs. I also believe this may not be the correct use of stderr. But I need the program to exit when an error has occurred.
Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {
[Code] ....
heres the function:
string ToString ( const char * format, ... )
{
char buffer[256];
[Code]....
these function do the same of the sprintf() function. but instead we use a variable for add the result, i want to return the result. when i use it:
string f;
f=ToString("hello world");
gives me several errors:
"error: crosses initialization of 'std::string f'"
"error: jump to case label [-fpermissive]"
So I have this code:
temp =count + " x " + name;
if (count > 0) { Stats.Inventory.Add(temp); }
Where Inventory is declared as
public static List<String> Inventory, Sellables;
and temp and count are declared locally as
double count = 0;
string name = string.Empty,temp = string.Empty;
An it throws an error
>Craft.exe!Craft.Stats.InventoryUpdate(string NewInventory) Line 166 + 0x73 bytesC#
My main questions is why? This is my first time using lists
Im doing a little game, casting dices etc. The problem is that the program will ask for player 1 then if i enter a name and enter it will ask for player two and so going on until i just press enter with a empty field and then continue the game.
The problem is i don't have any clue what code bits to start studying and how i shall lay it up, feels like i need a new string declaration automatically for each name.
I need to add the current date to the end of a string but I only need to add the day and not the year or month.
Put the code This is what i have
char date[9];
_strdate(date);
cout << date << endl;
I'm giving the replace option to my string:
void replace(string oldstring, string newstring) {
int stroldstringpos=b.find(oldstring);
b.replace(stroldstringpos,newstring.length(),newstring);
}
i have 1 error in these function that i'm confused. imagine the newstring size is more big than the oldstring, how can change the string, but only change the oldstring and add what left?
see these:
String test="hi hello world";
test.replace("hi","hello");
the result must be:
hello hello world
how can i change the replace function for it?
I am making a program that formats a string. I want to create a new 2 dimensional string that will have many other chars and strings in it beside the original string. Then I split the string up on the newlines and return it. Adding different parts to the 2d string e.g. I need to add five _ as chars not string then I need to add different things. First I use sprintf () to add as much as possible. And then I do what to add the rest?
View 13 Replies View RelatedHow to return as a pointer to a string?
View 5 Replies View RelatedI need a function to return a string..i need to pass input as "a,b,c,a,c,d,e" function should return out put as "a,b,c,d,e".
View 3 Replies View RelatedI am trying to code a function which will read a file on system and return its content back as string. Code is below.
Code:
char * readtxt(){
FILE * fptr;
char c;
static char txt[30];
[Code]....
I suppose txt variable is pointer. But I need to return the file content as string so the function structure should look like
Code:
returnType function(){
return "File Contents as String";
}
I am trying to code a function which will read a file on system and return its content back as string. Code is below.
char * readtxt(){
FILE * fptr;
char c;
static char txt[30];
int len=0;
fptr = fopen("C:UsersTestDesktopDev est.txt", "r");
[Code] ....
I suppose txt variable is pointer. But I need to return the file content as string so the function structure should look like
returnType function(){
return "File Contents as String";
}
How can I achieve this ?
PHP Code:
int processString(xxx)
{
//do something
return non-null terminated string length
}
To make the function work better we change its internals
PHP Code:
int processString(xxx)
{
//do something
return null terminated string length
}
This phenomenon can be observed by use of mutibyte to wide char conversions, string copy , concatenation functions of MS etc ....
Should I minus one in the return value of the second function to match both versions ?
I need a function to return a string
I need to pass input as "a,b,c,a,c,d,e"
function should return out put as
"a,b,c,d,e"
I try to make dll and install it under "Component Services". I tried to make method that return string but when i test it i don't get any result :
Code:
STDMETHODIMP CSimpleChat::CellMe(BSTR name, BSTR** helloMessage) {
CString temp = _T("Hi ");
temp += name;
temp += ", welcome to the simple chat server!";
BSTR str = temp.AllocSysString();
*helloMessage = &str;
return S_OK;
}
I'm trying to return a string to then call it on main function.
Code:
const char* coiso(int chave){
char str [50];
sprintf(str,"%d",chave);
char txt[50] = ".txt";
strcat(str,txt);
return str;
}
int main () {
const char* info = coiso(8);
printf("%s",info);
}
If I do a printf("%s",str) in coiso function it works but the following code doesn't work.
I've to use recursion function that return if the string has a same letters:
for example: - fff = true
- fFf = false
I did this but the return answer is always: NOT!
bool iSameLetters(char str[SIZE]) {
if(str[0]='