Iam meant to implement 3 methods that do the same thing differently
to read in a string and the string that is read from the keyboard must be terminated with an end-of-string character. Also, it should not
contain any new line character.

iam supposed to use fgets(), getchar() and scanf();

this is wat i have cum up with

#include <stdio.h>                 /*Include the standard I/0 header file */
#include <string.h>                /*Include the standard I/0 header file string library */

//The functions that are meant to be defined
char* toPLString(char * inputstring); 
int getInputBygetChar(char input[]);
int getInputByfgets(char input[]);
int getInputByscanf(char input[]);

       
int main(int argc, char *argv[]){
    char phrase[1000];
    char *token;
    
    printf("", getInputByscanf(phrase));
    printf("The sentence in Pig Latin is: ");
    token = strtok(phrase, " ");
    toPLString(token);
    printf("\n");

    system("Pause");
    return 0;
}
//method to convert to Pig Latin
char* toPLString(char * inputstring){
     char *toPLString = inputstring;
     while (toPLString != NULL){
           printf("%s%c%s", toPLString + 1, toPLString[0], "ay ");
           toPLString = strtok(NULL, " ");
           printf(" ");
     }
}

//Method to to read a string from keyboard and return number of characters read.
int getInputBygetChar(char input[]){
     int i;
    int letterCount;
    char letterToMatch;
    char string[4];
    
    letterCount = 0;
    while ( (i = getchar() ) != EOF){
          if (  i >= 'LetterToMatch')
             letterCount++;      
    }
        printf("Enter any string: ");
        scanf (" %c", string);
        printf("  \"%s\"\n", string);
        system("Pause");
        return 0;
   

}

//Method that uses the fgets method to read a string from keyboard and return number of characters read.
int getInputByfgets(char input[]){
    char text[4];
   puts("Enter the phrase to translate: ", stdout);
    fflush(stdout);
    if ( fgets(text, sizeof text, stdin) != NULL ){
       char *newline = strchr(text, '\n'); /* search for newline character */
       
       if ( newline != NULL ){
          newline = '\0'; /* overwrite trailing newline */     
       }     
       printf("text = \"%s\"\n", text);
    }    
    system("Pause");
    return 0;
    
}

/*Method that uses the scanf method to read a string from keyboard and return number of characters read.
*Scanf reads a character string. The scan terminates at whitespace. A null character is stored at the end
of the string. However, the input string size from a user is arbitrary.*/
int getInputByscanf(char input[]){
     char phrase[4];
	range = scanf("%c", &phrase[]);
		while (range != EOF)
		{
			range = scanf("%c", &phrase[])
		}
	return 0;

    
}

please help me implement these methods properly

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.