C++ :: String Function Isn't Working?

Dec 6, 2014

The function Reverse does seem to work. Its supposed to take the words in a sentence and then reverse them. For example: "This is nice" to "Nice is this." When I type "This is nice" I get " niceniceis nice"

#include <iostream>
#include <string>
using namespace std;

[Code]....

View 1 Replies


ADVERTISEMENT

C :: String As Parameter Not Working Properly

Oct 19, 2013

I want to alter a string inside a function, but it is not working.Here is the function:

Code:

#include <stdio.h>
void test (char *ch){
ch[0] = 0;
ch[1] = 1;
ch[2] = '';
}

[code]...

View 2 Replies View Related

C++ :: GF Flag Set - String Pooling Not Working?

Oct 20, 2013

I've created this little program.

#include <iostream>
int main(int argc, char* argv[]) {
char string1[] = "Hello";
char string2[] = "Hello";

[Code] ....

The idea, was to show that when you compile with the /GF flag set, string pooling is enabled, and the const char*'s which point to string literals would point to the same, read-only memory location. However, the addresses are still different.

Obviously, I'm compiling with /GF set. I'm using VC++2008 IDE if it makes a difference.

View 4 Replies View Related

C++ :: Revert A String Code Is Not Working

Feb 10, 2013

I created a .txt file that I called in.txt. It has the letters: a b c d e. I put it in the same folder as the c++ code below. I was hoping that I after I compile and run the code, the in.txt file would read: e d c b a. Unfortunately, it doesn't. Even when I give the ofstream file another name, it does not create another text file.

Code:
#include<iostream>
#include<fstream>
#include <limits>

[Code].....

View 7 Replies View Related

C :: Mod Function Not Working

Nov 27, 2013

Code:
#include <stdio.h>
int main() {
int m,c;

for(c=0;c<100;c++) {
m = c % 10;
printf("%d ",m);
}
return(0);
}

When I run this code in my compiler, I get the first nine or ten numbers, and then after that it just spells out the letters in my name in different sequences over and over.

View 3 Replies View Related

C++ :: Calling Another Function Within A Function Not Working

Feb 20, 2013

I have two functions bool check_key(string cKey, string eKey) and bool check_digit(char digit1, char digit2), and I have declared both of them globally (is this the right terminology?) right after the "using namespace std;" and right before the "int main(){".

In the first one, I called the second one . But it is giving me the error: "no match for call to `(std::string) (int&)' ".

Code:
bool check_key(string cKey, string eKey) {
if(cKey!="" && eKey=="") return false;
if(cKey=="" && eKey=="") return true;
if(cKey=="" && eKey!="") return true;
if(cKey.length()!= eKey.length()) return false;
bool flag=true;

[Code] ....

View 2 Replies View Related

C :: Recursive Function Not Working

Nov 9, 2013

the functions checks if the word is a palindrome like"level" "madam" etc. but with input "dfdfdfdffdfd" my recursive function fails.

Code:

/* main.c - Created on: Nov 9, 2013 - Author: Kaj P. Madsen*/
#define MAX 100
#include <string.h>
#include <stdio.h>
int checkPalindrome(char checkString[MAX]);
int checkRecPalindrome(char checkString[MAX], int strLgt, int a);
}

[code]....

results from "dfdfdfdffdfd" added some print to see that its the variables a and strLgt not functioning properly

Code:

dfdfdfdffdfd.
The word is not a palindrome(iterative)
strLgt: 11 a: 0
a: d strLgt: dstrLgt: 10 a: 1
a: f strLgt: fstrLgt: 9 a: 2
a: d strLgt: dstrLgt: 8 a: 3
a: f strLgt: fstrLgt: 7 a: 4

The word is palindrome (recursive)

View 4 Replies View Related

C :: Rounding Function Not Working

Oct 12, 2013

Why the roundf function is not successfully rounding my numbers.

Code:
#include <stdio.h>
#include <math.h>
//function declarations
void CelToFah (int ctemp, int ftemp);

[Code]....

it produces a correct number when called, but it is not a rounded number, the roundf((float)cel) does nothing. I get the same number with and without it.

View 6 Replies View Related

C++ :: Remove Function Not Working?

Jan 24, 2014

Below is my .h file and the code below that is my function that I'm having troubles with. Its suppose to take in a users topic and see if that topic exists, if it does exist then find the keyword, commentcompare will find where that keyword is and delete the comment. However its not deleting anything and its returning temp is NULL.

class comment //adds a comment
{
public:
comment(char * create_comment);

[Code]...

View 3 Replies View Related

C++ :: Function Call Is Not Working

Oct 15, 2013

i think my function call is not working and i dont know how to fix it. Basically i want it to output my getstudent function and once i get the information i want it to output with the displaystudent.

#include <iostream>
#include <string>
using namespace std;
void displayStudent(Student x) {
cout << x.first << ' ' << x.last << endl;
cout << x.id << endl;

[code]....

View 6 Replies View Related

C++ :: Delete Function Not Working?

Oct 9, 2014

making my delete function work. My program does compile but my delete function doesn't work. I haven't finished my last two functions because I am focusing on the delete but how to Sell a title and print the value of all sold titles would be nice as well.

#include <iostream>
#include <cstdlib>
#include <string>

[Code].....

View 2 Replies View Related

C/C++ :: Call To Function To Calculate Fx/f Is Not Working

Apr 23, 2014

I am writing a program where f is the frequency and the x has the values as well. Now I am calculating the mean which is summation fx divided by summation f. I have the two functions working correctly but the getmean function is not working. It suppose to divide fx/f . check the code below

#include <iostream>
using namespace std;
const int SIZE=5;
class statisticalOperator{

[Code]....

View 2 Replies View Related

C :: Concatenate Strings In Array (2D) - Function Not Working Right?

Sep 6, 2013

I have a function that concatenate the strings in an array(2D)

Ex 1: Sean Connery Micheal King James Wood

Result: SeanConnery MichealKing JamesWood ...

The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this

Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..

It adds to first name. Why?

Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()

[Code] .....

View 4 Replies View Related

C++ :: Average Calculation Function Not Working As Expected To

Dec 16, 2013

[URL] ....

My calculation function will not work like i wanted it to. It gives me 0 or a crazy number.

this is the function here:
the entire code is on the link:

double calculations(data&avgs) //Calculates the students grade into a final grade
{
int avg1;
int avg2;
int avg3;
int lab1;

[Code] ....

View 12 Replies View Related

C :: Get Binary Number And Change Its Bits - Calling A Function Not Working

Apr 8, 2013

This code gets a binary number and change its bits. I have a problem with the "bits_up" function . Why this function not working?

Code:
#include <stdio.h>
#include <stdlib.h>
int bits_up(uint first,uint last,int *ptr);
int main(void)
{
uint first,last,bitUD;
int InputBinNumber[4],updatedNum[4];

[Code] ....

View 5 Replies View Related

C++ :: Count Function In Program Not Working Properly - Counting Blank Nodes

May 9, 2013

I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.

This is my main.cpp file

int main() {
string word;
cout<<"Enter a word"<<endl;
cin >> word;
string filename;

[Code] .....

View 9 Replies View Related

C++ ::  Class Safe Array Type Print Function Not Working When Called

Oct 22, 2013

I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.

Header File:

//safearrayType Header File
class safeArrayType {
public:
void print() const;
void insertAt(int location, const int& insertItem);
safeArrayType(int firstPlace=0, int maxPlace = 100);

[Code] ....

ResultsEnter the first bound of yourlist: -3(this was my input)
Enter the last bound of yourlist: 7(this was my input)

Press any key to continue...

View 1 Replies View Related

C++ :: Calling A String In One Function Into A New Function

Oct 24, 2013

How would I call a string that sits within a switch loop in the main function, into a separate function?

Like this:

void statistics() {
cout << "Here are the statistics for your entry: " << endl;
cout << "
The size of your entry is " << s.length() << " characters." << endl;
}

I am calling string s from this:

switch (toupper(myChoice)) {
case 'A': cin.ignore();
cout <<"
Please enter your text: ";
getline(cin, s);

[Code] ....

View 2 Replies View Related

C++ :: How To Pass A String To A Function

Sep 12, 2013

How can I pass the name from the user input to the constructor ?

Code:
#include <iostream>
#include <string>
using namespace std;
class myClass {

[Code]....

View 6 Replies View Related

C :: Replace String Function

Dec 23, 2014

I am new to C, but I recently completed an exercise from a book that finds a string in another string, removes the string, and replaces it with another string.

Code:

// Replace String
#include <stdio.h>
#include <stdbool.h>
bool replaceString (char source[], char s1[], char s2[])
}

[code]....

View 8 Replies View Related

C++ :: Need A Function To Return A String

Aug 13, 2014

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".

View 3 Replies View Related

C++ :: String To Double Function

Jul 3, 2014

Because MinGW C++ doesn't have the atod() or atoi() functions for some reason, I had to code a string to double function myself.

double stringToDouble(std::string input) {
bool isDecimal;
int decimalLoc;
double output = 0;
double n;

[Code] ....

View 1 Replies View Related

C/C++ :: Returning A String From A Function?

Mar 23, 2015

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

[Code].....

The code above is my attempt. If I can get the above code to work

View 5 Replies View Related

C :: Function To Detect Subsequence String

May 1, 2013

So I need to write a function that has 2 arguments that are strings. It returns 1 if the first string is a subsequence of the second string, and 0 otherwise.

For example, given 2 strings like "foobar" and "obr", the function should returns 1 whereas "foobar" and "obo" returns 0.I have tried writing the code myself,

Code:
int sub(char *s, char *t) {
int i;
char *p;
for (i=0; t[i] != ''; i++) {
p=strchr(s,t[i]);
if (p==NULL)
return 0;
else
strcpy(s,p);
}
return 1;
}

So my strategy is as follows:
1. Find the first letter of the second string in the first string (foobar).
2. If there's a match then continue to search for the second letter of the second string starting from the index of the first letter plus 1. (obar). Otherwise return 0,.........

However the function always return 1 no matter what the input strings are.

View 11 Replies View Related

C :: Passing A String To A Function From Main?

Mar 30, 2014

i would like to know if i need to dynamically allocate a string in main before passing it to a function that i have created.

in that function i just read the string and do not change any chat in it.

View 2 Replies View Related

C :: Reverse A String - Function Is Not Getting Called

Aug 29, 2013

I am new to C and trying to reverse a string but the function is not getting called.. the console says :

Enter a stringabhi
bash: line 1: 229 Segmentation fault (core dumped) ./program

Code:
#include<stdio.h>
#include<math.h>
#include<string.h>
char* reverseString(char input[]);
void main()

[Code] ....

View 6 Replies View Related







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