C++ :: Function Should Not Display Anything But Resulting String Is Returned As A Result
Mar 2, 2014
c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:
A function recive: "housesinkbuildings" .The function returns: "house=sinkb=uildi=ngs" in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.
View 2 Replies
ADVERTISEMENT
Feb 7, 2012
Code:
it = m_CoopTable->m_SparseMap.find(s);
if (it != NULL) //Error
{
return false;
}
This gives me compile-time error. it is an iterator to a hash_map
View 9 Replies
View Related
Apr 19, 2014
I created class called students which suppose to store students names of in array but when I call the display function it display only the first name. but I want it to display names depending on the array size.
#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
[Code]....
View 3 Replies
View Related
Nov 6, 2014
I am trying to make the code below display the result with decimals. I tried using setprecision, but I am not too sure where to put it. I placed it in cout section where the answer is but it still doesn't come out correctly.
#include <iostream>
using namespace std;
//*Delcare function prototype*
int ConvertToCentimeters (double, double );
//declare exception class*
class NegativeNumber
[Code] ....
View 4 Replies
View Related
Apr 7, 2013
Is it possible to prompt information from user then display the result in a one dimensional array form? If yes, how should i link them together?
View 7 Replies
View Related
Aug 28, 2014
I have this int type function that returns a number. It returns the value 2 for now but later it will return more variety of values. How do I use the value it returned? I'm not sure of the proper syntax.
View 5 Replies
View Related
Dec 6, 2013
So, I'm in the midst of implementing my own malloc() and free() functions, but I'm having a hard time with the syntax of getting the address that malloc returns. Whenever I check the address, it's 0 Here's the code:
Code:
char *word = malloc(10);
int address = *word;
printf("%d",address);
The reason I want the address is so that I could store it in a data structure for further usage when I'm dealing with different cases for the free() function. Or is there another way to do this?
View 5 Replies
View Related
Feb 12, 2014
I am just trying to make a simple two player game. First player enters the movie and second player guesses it by using some basics of C++.
movie[] = entered by player 1.
movie_temp[]= a temp array with '_' in it. It updates after every guess by player 2.
MY PROBLEM: Please refer the main function where I called the function movie_check().
This updates the life after every guess. I want the same to happen for my movie_temp array.
When i run this program, only the lives are updated properly, on correct guess the lives are not reduced, but in next turn the array_temp is not updated and the same array is displayed again and again after each gas.
How to create a function which return array and save it in movie_temp (just as I did for life).
IDE: Code::Blocks
Compiler: GCC Compiler
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
void display_movie(char movie_temp[], int);
void display_life(int);
int win_player2(char movie_temp[]);
[Code] ....
View 4 Replies
View Related
Nov 6, 2013
Despite seeing the correct data in gdb when I
Code:
p *(DownloadFileChunkResponse.DownloadFileChunkResult)->__ptr@100
The following C code gives me a SEG FAULT
Code:
calloc(NewMediaChunk, ChunkSize);
memcpy((void *)NewMediaChunk,
*(DownloadFileChunkResponse.DownloadFileChunkResult)->__ptr, ChunkSize);
How I got this wrong. BTW The data I am attempting to memcpy is the frontend of an MP4 file containing a number of NULLS.
Code: 00 00 00 30ftypmp42 00 00 00 00mp42mp41 00 00 dfree
BTW ChunkSize is 64000
View 9 Replies
View Related
Oct 9, 2014
can we pass two linked lists as argument in a member function to add two linked lists? and how to access them both in the function??
View 1 Replies
View Related
May 3, 2013
I'm working on a CGI application. I'm trying to test my input with a switch statement and output the result with html tags to populate a web page. From within the switch, I've coded as follows:
HTML Code:
switch(mFunc) {
case 0:
cout << "<p><b>YOU ENTERED THE FOLLOWING TO BE CALCULATED:</b></p>" "<h2>"<< number1 <<"+" << number2 << "</h2>" << endl;
break;
case 1:
cout << "You've entered" << number1 <<"-" << number2 << "to be evaluated" << endl;
break;
I know that I'll need to put this in an html body with a content type as such:
HTML Code:
cout << "Content-type: text/html
";
cout << "<html><body>
";
Am I able to do that directly inside of the switch statement?
View 11 Replies
View Related
Mar 28, 2013
I have this simple code here:
Code:
#include <iostream>
int multiply (double x, double y) {
double result = x*y;
return (result);
[Code] ....
I get the answer 5.94 (which is what I'm looking for). I can't work out why the first example is not outputting a decimal number. I have set the variables as a double so I just can't see why this is not working for me.
View 1 Replies
View Related
Aug 28, 2013
I just want to practice in the language so i wrote this simple function that computes the factorial result of a certain number. The problem is that for all numbers > 20, the results are wrong ( < 20 all good).
I already learned that normal "long" type in c is more like 32 bit int and not 64 bit like a long type in java. so I used here a "long long" type.
why am I getting strange results above the number 20? isn't 64 bit enough to hold those numbers?
Code:
long long factorial(int n);
int main() {
long long result = factorial(20);
printf("%lld",result);
[code] ...
for 21 i get: -4249290049419214848
where the right result shoud be: 51,090,942,171,709,440,000
View 8 Replies
View Related
Nov 14, 2013
I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.
I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.
View 1 Replies
View Related
Jun 14, 2013
It's been about two years since I last program c, now I need to do it for a basic project. How would I print out one letter in a string?
For example lets say I have a string called str=[Hello]. I want to display the third letter so just the "l". Here's what I have so far:
Code:
#include<stdio.h>
int main() {
char str[50] = "Hello";
printf("The third letter is : %s
",str[3]);
return 0;
}
View 2 Replies
View Related
Mar 6, 2015
How can i display a string per line on the .txt i made? There are 2 .txt files, the one has: John Finn Xach The other is: password1 password2 password3 Question is: How can i display, let's say, i input "John" so it will display something like this "John's password is password1" or if i input Xach, "Xach's password is password3" When i use something like :
Code:
while(getline(passwordFile, str))
{cout<< username <<" password is " << str;
break;
}
It will work for when i input "John", but it doesn't work if I input "Finn" or "Xach"
EDIT: I tried this one:
Code:
while(getline(userFile, str1) && (passwordFile, str2))
{
cout<< str1 <<" password is " << str2;
break;
The output would be: Finn password is password1
It iterates the username but not the password.
View 7 Replies
View Related
Mar 2, 2013
Why I cannot do this to display each element of my char string? What is the proper way?
Code:
char str[SIZE];
int i;
for(i=0; i<SIZE; i++)
{
printf("%s", str[i]);
}
View 4 Replies
View Related
Apr 19, 2014
I created class called students which suppose to store students names of any sizes in an arrey but when I call the display function it does not show the names.
#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
class students{
public:
string names[SIZE];
[Code] ......
View 1 Replies
View Related
Apr 7, 2015
Im trying to convert a base 64 string to an image and store in a gridview control (windows 8)
instead of an image im seeing text in the control
Windows.UI.Xaml.MediaImaging.Bitmap
convert base 64 string to bitmap
public async Task<BitmapImage> Base64ToImage(string base64)
{
var bitmap = new BitmapImage();
var buffer = Convert.FromBase64String(base64);
using (var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream()) {
[Code] ....
View 2 Replies
View Related
Nov 18, 2013
I am working on my final project for my class and after finally getting it to compile with no errors to finding examples/tutorials and following skeleton code I cam encountering a problem.
The program runs, asks all the correct questions but when it displays the base pay and total pay for all 3 employees it comes back as ( -1.0743 blah blah )
When they work over 40 hours it works correctly but when they work under 40 hours it displays those weird numbers in those sections.
// Kevin Johnson -- Overtime Pay -- Final Assignment
// Created 11/14/2013 // Edited 11/17/2013
#include "stdafx.h"
[Code]....
View 9 Replies
View Related
Apr 22, 2012
Why is it not okay to return void? Most compilers will probably let you (gcc does) but it gives you a warning that you aren't supposed to. Most languages allow you to return void.
Something like
Code:
void log(const std::string & txt){ std::cout << txt << std::endl; }
//C++ way to do it
void bar(int i){
[Code].....
View 10 Replies
View Related
Oct 18, 2013
This is my code:
Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation
[Code] ......
And I keep getting this error:
Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status
View 5 Replies
View Related
Mar 11, 2014
I've had with visual studio but nothing seems to be working. No matter what I do even with simple programs, like Hello World, I'm always getting an error about a .pch header file.fatal error C1083: Cannot open precompiled header file: 'DebugConsoleApplication1.pch': No such file or directory
This is only for one of the programs I've made but I'm pretty new to programming and I've not even used the header files for anything so I have no clue how to resolve this problem.
View 2 Replies
View Related
Jul 14, 2014
I have some struct which contains: void *elems (basically a pointer to an array of contiguous memory).
I want to use bsearch to return a pointer, and then somehow figure out where in the array that value is. Having a pointer in this case isn't enough, I need to know what the index is. I've tried a number of things:
int index;
void *value = bsearch(key, start_ptr, cv->count, cv->elemsz, cmp);
index = &value - &start_ptr;
return index; [
Replacing the second line with:
// in the first instance
index = (char*) value - (char*) start_ptr;
// in other instances...
index = ((char*) value - start_ptr))/cv->elemsz)
But nothing works.
View 6 Replies
View Related
Sep 15, 2014
I call a function that returns a string, and I can print it out fine, but I want to test the result of the function to see if it returns 0. But I can't just call the function again (GetNextToken(b)) because it will generate a different token. I can't allocate space for the string because I'm not sure what the size of the returned string is going to be.
Basically I want to see if the GetNextToken(b) returns 0, and if it doesn't then print the string. And running GetNextToken(b) again will give a different result.
Code:
int main(int argc, char **argv) {
SomeStruct* b = CreateStruct(argv[1],argv[2]);
printf("HERE %s", GetNextToken(b));
View 3 Replies
View Related
May 4, 2014
What does the C++ standard say about returned temporal objetcts's lifetime ?For example, in this code:
#include <iostream>// Object cout, manipulator endl
using std::cout;
using std::endl;
class C {
private:
[code]....
Here, the temporal object C returned by function f() still lives when function h() is called and is destroyed inmediately after function h() returns to his caller (the function main()). So, it seems that a returned temporal object lives while it is used and it is destroyed when not used (in the next sentence of the sentence that call the function that returns the temporal object). Does the C++ standard specify that this must be the behaviour of C++ compilers?
View 1 Replies
View Related