#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
#define MaxStringLength 500
int main( int argc, char** argv )
{
char userString[MaxStringLength] = "";
char charString;
int i = 0;
int numOccur = 0;
printf( " Enter any string: ");
while( i %26lt; MaxStringLength)
{
userString[i] = getchar();
if( userString[i] != '\n' )
i++;
else
break;
}
userString[i] = '\0';
printf( " Enter any character: ");
scanf( "%c ", %26amp;charString);
i = 0;
while( userString[i] != '\n' %26amp;%26amp; i %26lt; MaxStringLength )
{
i++;
if( userString[i] == charString )
numOccur ++;
}
printf( "In the following string: \"%s\"\n", userString );
printf( "The character \'%c\' appears %i times", charString ,numOccur );
return( 0 );
}
**/ That is my program. Whats happening is once i get the user input for what character theyd like, it doesnt keep running, you have to like type something in for it to continue runningthrough. Help!
Problems with my c++ program not executing the right way...could anyone tell me how im getting this problem?
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
#define MaxStringLength 500
using namespace std; // using namespace container.
int main( int argc, char** argv )
{
char userString[MaxStringLength] = "";
char charString;
int i = 0;
int numOccur = 0;
printf( " Enter any string: ");
while( i %26lt; MaxStringLength)
{
userString[i] = getchar();
if( userString[i] != '\n' )
i++;
else
break;
}
userString[i] = '\0';
printf( " Enter any character: ");
scanf( "%c ", %26amp;charString);
i = 0;
while( userString[i] != '\n' %26amp;%26amp; i %26lt; MaxStringLength )
{
i++;
if( userString[i] == charString )
numOccur ++;
}
printf( "In the following string: \"%s\"\n", userString );
printf( "The character \'%c\' appears %i times", charString ,numOccur );
system("pause"); // this function call pauses execution.
return( 0 );
}
done. you needed to use the system("pause"); call in your program.
parts of a flower
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment