ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 28 Apr 2017 My Price 9.00

the program changes the characters

Hi,

I’m doing a problem currently and I am being asked to create a program which opens a file the user enters and searches that file for words that end in ed. I’m trying to make it so that the program changes the characters to all lower case before it searches so that words ending in ED, Ed, and Ed will also be returned.

#include 
#include 
#include 
#include 
#define Max_Lines 1000
#define Max_Length 500

int read_file( const char *filename, char* word_array[] ); // function to read the file

void lower_string( char* word_array[] );

int main( void )
{
int i;
int number_of_lines;
int length;
char filename[ 300 ];
char* word_array[ Max_Lines ];
int opened = 0;

while ( opened != 1 ){
printf( "Please enter the file name you wish to search:n" );
scanf("%s",filename);

if ( -1 == ( number_of_lines = read_file( filename, word_array ) ) ){
printf( "The file name entered could not be opened.n" );
opened = 0;
}
else
{
opened = 1;
}
}

printf( "nThe words ending in "ed" are as follows:n" );

for ( i = 0; i length = strlen( &word_array[ i ][ 0 ] );
if ( strcmp( &word_array[ i ][ length - 2 ], ( "ed" ) ) == 0 ) {
printf( "%sn", &word_array[ i ][ 0 ] );
}
}
return 0;
}

void lower_string( char* word_array[] )
{
int i;
while ( word_array[ i ] != '' ) {
for ( i = 0; word_array[ i ]; i++ ) {
putchar( tolower( word_array[ i ] ) );
}
}
return i;
}

int read_file( const char *filename, char* word_array[] )
{
char buffer[ Max_Length ];
int i = 0, length;
FILE * filePtr;
filePtr = fopen( filename, "r" );

if ( !filePtr ) {
return -1;
}

while ( !feof( filePtr ) ){
fscanf( filePtr, "%s", buffer );
length = strlen( buffer );
word_array[ i ] = ( char* )malloc( length + 1 );
strcpy( word_array[ i ], buffer );
++i;
}

fclose( filePtr );

return i;
}

Answers

(11)
Status NEW Posted 28 Apr 2017 05:04 AM My Price 9.00

-----------

Attachments

file 1493358267-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)