APlusGrades

Not Rated (0)

$15/per page/Negotiable

About APlusGrades

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

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing,Foreign Languages,Geography,Geology,Health & Medical,HR Management,Law,Management,Physics,Programming,Science,Statistics Hide all
Teaching Since: Jul 2017
Last Sign in: 266 Weeks Ago, 3 Days Ago
Questions Answered: 1850
Tutorials Posted: 1850

Education

  • Graduate in Biology and Nutrition, MBA Finance
    Florida State University
    Aug-2000 - Jul-2007

Experience

  • Ass. Relationship Manager
    Penn-Florida
    Mar-2009 - Feb-2016

Category > Programming Posted 18 Jul 2017 My Price 12.00

create a program

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

Not Rated (0)
Status NEW Posted 18 Jul 2017 04:07 PM My Price 12.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â-----------  -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I

Not Rated(0)