here is the other problem project im sure it's something small im missing.
for some reason there is no print out for the most used letter
demo.cpp

/* File Name: demo.cpp
 Chapter No. 12 - Exercise No. 9
 Programmer:         Carl Sue
 Date Last Modified: Mar 23, 2010
 
 Problem Statement: (what you want the code to do)
 Write a function that accepts either a pointer to a c-string or
 a string object as it's argument the function should return the
 character that appears most frequently in the string demonstrate
 the function in a complete program.

 Input validation: do not accept negative numbers for test scores.
 
 
 Overall Plan (step-by-step how you want the code to make it happen):
 1.
 2.
 3.
 etc.
 
 Classes needed and Purpose (Input, Processing, Output):
 
 
 */

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

char mostused(char*sentance);
char mostused(string sentance);

int main(int argc, char * const argv[]){
	string test1 = "hello my name is Carl";
	char test2[30] = "hello name is Carl";
	char output1, output2;
	output1 = mostused(test1);
	output2 = mostused(test2);
	cout << output1;
	cout << output2;


	return 0;
}


char mostused(char*sentance){
	int i, temp, flag = 1, numLength = strlen(sentance);
	int d = numLength;
	while( flag || (d > 1)){
		flag = 0;
		d = (d+1) / 2;
		for (i = 0; i < (numLength - d); i++){
			if (sentance[i + d] > sentance[i]){
				temp = sentance[i + d];
				sentance[i + d] = sentance[i];
				sentance[i] = temp;
				flag = 1;
			}
		}
	}
	int array[255] = {0};
	int j, max, index;
	for(j = 0; sentance[j] != 0; j++){
		++array[sentance[j]];
	}
	max = array[0];
	index = 0;
	for(j = 0; sentance[j] != 0; j++){
		if( array[j] > max){
			max = array[j];
			index = j;
		}
	}
	cerr << (char)index;
	return (char)index;

}

char mostused(string sentance){
	int i, temp, flag = 1, numLength = sentance.length( );
	int d = numLength;
	while( flag || (d > 1)){
		flag = 0;
		d = (d+1) / 2;
		for (i = 0; i < (numLength - d); i++){
			if (sentance[i + d] > sentance[i]){
				temp = sentance[i + d];
				sentance[i + d] = sentance[i];
				sentance[i] = temp;
				flag = 1;
			}
		}
	}
	int array[255] = {0};
		int j, max, index;
		for(j = 0; sentance[j] != 0; j++){
			++array[sentance[j]];
		}
		max = array[0];
		index = 0;
		for(j = 0; sentance[j] != 0; j++){
			if( array[j] > max){
				max = array[j];
				index = j;
			}
		}
		cerr << (char)index;
		return (char)index;
}

thanks for any pointers

There are many ways you can make your life easier on this one. I'll focus mostly on 62-77. You should make your array only 26 members long. That way there is not a lot of wasted array space to confuse the matter.
There's an easy mapping between chars and an appropriate array index, so if you have 'a' and you want to get to 0th index what would you subtract?
Next for line 65 you want to subtract that same quantity from "sentance[j]" to get an appropriate index. Account for all your arrays being 26 elements long in the loops.

Once you get to 76 transform the position in the alphabet you get back to a letter and return it. In following these steps I got the correct answer of 'l' for the phrases.

Now you can either make all the same changes to the other function or when calling the string version, use the c_str() method to get the null-terminated version of the string and call the char * version with that data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.