C++ :: Use Recursion Function That Return If String Has Same Letters

Aug 12, 2013

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]='')
return true;
else {
if((str[0] && iSameLetters(str+1) == str[0]))
return iSameLetters(str+1);
return false;
}
}

View 3 Replies


ADVERTISEMENT

C++ :: Return A Node Using Recursion

Mar 27, 2013

So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have Code: ​/*function 3-takses as input the pointer to the root of the tree and returns a pointer to the node with the minimum value*/

CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL; //node of minimum value
if(SP== NULL){ // if there is a node, begin comparing
return NULL;
}
else{
if(SP->data<SP->left->data){ //if the node has smaller value than its left child
min = SP; //update node of minimum value

[code].....

no matter where i call my function i get errors like unhandled exception at some memory. how to use recursion in this?

View 6 Replies View Related

C++ :: Want To Return A Node Using Recursion

Mar 28, 2013

So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have

CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL;//node of minimum value

if(SP== NULL){// if there is a node, begin comparing
return NULL;

[Code] ....

No matter where i call my function i get errors like unhandled exception at some memory. How to use recursion in this?

View 1 Replies View Related

C/C++ :: Function That Generates A Random String Of Uppercase Letters

Apr 19, 2014

I need to write a C function that generates a random character array (i.e. string) of uppercase letters - getchar and putchar are the only IO functions that I can use. Below is what I have already - I am iterating for as many times as I am required to, and am modulating rand() by 25, (total letters in the alphabet). I'm trying to see how to get the random letter from the % 25, and also how to do this without toupper() [not sure if I can use that function].

void getRandomStr()){
char str[40];
for (int i = 0; i < 40; i++){
char c = rand() % 25);
str[i] = toupper(c);
}}

View 5 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++ :: Creating 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 2 Replies View Related

C :: Return A String To Then Call It On Main Function?

May 26, 2013

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.

View 10 Replies View Related

C/C++ :: Why To Use Return Type For String Function As Char

Oct 6, 2012

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()?

View 4 Replies View Related

C++ :: Function To Return String - File Size

Feb 24, 2012

Where i can get ready function, which return string, which describe size of file?

For example
4 = 4 b
1045 = 1,01 Kb
and etc.

View 3 Replies View Related

C :: Compute Permutations Of Any String Entered - Function Will Not Return A Value

Jun 11, 2013

This is my program, for now it is intended to compute permutations of any string entered, but the function ox will not return the final x value. ox is the function that actually computes the permutations so the return of the x value is critical.

Code:
#include<stdio.h>
#include<string.h>
int ox(int x);
int main() {
int x;
char input[10];

[Code] .....

View 2 Replies View Related

C :: Program For Counting Vowels In A String Using Recursion

Jul 31, 2014

program for counting vowels in a string using recursion ?

View 12 Replies View Related

C++ :: Reverser Function Using Recursion?

May 8, 2014

So i have a program it works which takes in a word reverses it prints it out. BUT! the problem is that the program is without recursion. convert the function into recursion.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

[Code].....

View 2 Replies View Related

C :: Will Return Root Statement At End Ever Return Value Other Than Value Passed To Function?

Mar 29, 2013

I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?

Code:

#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}

[code]....

View 4 Replies View Related

C++ :: How Do Function Count Factorials - Recursion

Apr 3, 2013

How do function count factorials in this program?

#include<iostream>
#include<conio.h>
using namespace std;
void main(){
unsigned int factorial(unsigned int value);

[Code] .....

View 7 Replies View Related

C++ :: Function Causing Infinite Recursion Crash

Oct 24, 2014

This function is apparently causing infinite recursion, but I have no clue what's causing it:

Code:
int pow( int base, int exp ) { int somevariable = pow(base,exp-1);
if (exp == 0) {
return 1;
}
else {
return base * pow(base,exp-1);
}
}

View 10 Replies View Related

C++ :: Linked List - Recursion For Search Function

Mar 19, 2013

I have a linkedList search function given and I am having a little trouble getting it to work. I've made a few attempts with no success. Given normal search code:

template <class Type>
bool orderedLinkedList<Type>::search(const Type& searchItem) const {
bool found = false;
nodeType<Type> *current; //pointer to traverse the list

current = first; //start the search at the first node

[Code] .....

My attempt to make it a recursive search:

template <class Type>
bool orderedLinkedList<Type>::search(const Type& searchItem) const {
//bool found = false;
nodeType<Type> *current; //pointer to traverse the list
current = first; //start the search at the first node

[Code] ....

View 3 Replies View Related

C :: How To Restrict Input Of A String To 2 Letters

Mar 6, 2015

I'm doing error checks in C and I'd like to know how to restrict the input of a string to 2 letters and if it is exceeded, i'd like to loop and ask for the code to be re-entered.

Code:

for (i = 0; i < code7; i++)
{
printf("Enter number of items: ");
scanf("%d", &item_qty[i]);

[Code].....

View 2 Replies View Related

C++ :: How To Count Letters Of Alphabet In A String

May 5, 2014

I am creating a program where I count all the letters of the alphabet from a user submitted string.

How would I go about this?

I am completely new, so simplicity is best. I am suppose to use arrays.

View 4 Replies View Related

C++ :: Generating String Of Random Letters

May 1, 2014

My problem says: Have the user enter a number from 1-80 then print out a string of random letters(a to z lowercase) of that length.

I have been able to enter the number and output the correct amount of letters but i can't figure out how to get them to be in a random order and not in alphabetical. Here is what I have so far.

#include <iostream>
using namespace std;
int main() {
int i=0;
int num;
cout<<"How many letters do yu want in your random string?";

[Code]....

View 1 Replies View Related

C++ :: How To Turn A String Word Into Letters

Dec 9, 2013

I'm having trouble trying to turn a word into letters. I've seen other posts but they deal with a sentence and it only outputs the words only. What I want to know is how do they take a word (Ex: "word") and break it into individual letters, where I want to store them in a vector of string?

If it's not too much trouble, I would prefer without using pointers or "std:: " marks, since I am trying to avoid pointers and I'm using "using namespace std" all the time.

Ex:

In the example "word", it should output into:

"w"
"o"
"r"
"d"

and I will push them back into a vector of string where each vector element contains a letter.

View 2 Replies View Related

C :: Converting A String Array Into Uppercase Letters From File

Apr 19, 2013

I am new to coding Here is the problem. Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

Here is my code so far but i am only returning the last line of text capitalized from the file. I am trying to get the program to display all of the three lines of text from the file capitalized. The program displays the file correctly before i try and convert everything toupper();

Code:

Code: #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21];
int i;
FILE *inFile;

[Code]...

View 6 Replies View Related

C :: Find Number Of Capital Letters And Punctuations In A String

Jan 28, 2015

write a C program which repeatedly reads in sentences from the user and reports on how many capital letters are in the sentence and how many punctuation characters. Your program will stop asking for input once the user has entered in a blank line. Consider the following example usage with the program. User input is marked in underline:

Enter a sentence: John and Mary went to Fred's house.
You used 3 capital letters and 2 punctuation characters.
Enter a sentence: I like A&W more than McDonald's.
You used 5 capital letters and 3 punctuation characters.
Enter a sentence:
Good bye!

Hint: make use of the standard C functions ispunct and isupper. Other requirements. You must make two functions.

Make a function called find_characters, which has a return type of void, and which has three parameters: one of type char * (a string to find characters in), one of type int * (a reference to int variable indicating how many capital letters are in the string) and the last one also of type int * (a reference to an int variable indicating how many punctuation characters are in the string). Your find_characters function should scan the string and update the two variables it has references to.Make a main function.

This function should repeatedly read in a string from the user, call your find_characters function, and output the information returned to it by the find_characters function indicating how many capital letters and how many punctuation characters were in the string. Your main function should stop reading in input when the user enters in a blank string (i.e., the user just hits enter without entering anything else in). You may assume that the user will not enter in a sentence longer than 100 characters

Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

int main(void) {

[Code] .....

View 9 Replies View Related

C++ :: Allow User To Enter A String And Output In All Uppercase Letters

Oct 24, 2014

/* Program is to let the user enter a string and will output the sting in all uppercase letters. */

#include <cctype>
#include <iostream>
#include <string>

using namespace std;
char str1[80];

[Code] ....

I am trying to get the cin.get working where the user is allowed to enter an 80 character string and how to do that.

View 1 Replies View Related

Visual C++ :: Convert String Of Uppercase Letters Into Its Corresponding Lowercase

Apr 26, 2014

Write A Program which converts a string of uppercase letters into its corresponding lowercase.Using pointers to access the members of the Array.

Write A program that reads eight float numbers into an array and then print out the second,fourth,sixth and eight members of the array,

And Sum of the first,third,fifth,and seventh. Using pointers to access the members of the array.

View 2 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.

Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)

How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?

I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.

Code:
for(i = 0; i < strlen(unscrambledWord); i++) {
if(unscrambledWord [i] == c) {
Stars[i] = c;
} }

View 1 Replies View Related

C++ :: Convert Input String Into A Form - Capital And Lower Case Letters

Mar 27, 2013

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?

View 3 Replies View Related







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