Question

Please help me for this homework problem, thanks!! Instruction:(use visual studio or gcc) Code and Problem:...

Please help me for this homework problem, thanks!!

Instruction:(use visual studio or gcc)

Code and Problem: (please copy to visual studio, thanks)

#include <stdio.h>
#include <string.h>

#pragma warning(disable : 4996) // compiler directive for Visual Studio only

// Read before you start:
// You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully.
// All instructions are given above the required functions, please read them and follow them carefully.
// You shoud not modify the function return types or parameters.
// You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer.

// Global Macro Values. They are used to define the size of 2D array of characters
#define NUM_STRINGS 4
#define STRING_LENGTH 50

// Forward Declarations
void initializeStrings(char[NUM_STRINGS][STRING_LENGTH]);
void printStrings(char[NUM_STRINGS][STRING_LENGTH]);
void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH]);
void encryptStrings(char[NUM_STRINGS][STRING_LENGTH], int);
void decryptStrings(char[NUM_STRINGS][STRING_LENGTH], int);
int splitAndPrintSentences(char s[NUM_STRINGS*STRING_LENGTH]);
void inputMatrix(int matrixA[3][3]);
void determinant(int matrixA[3][3]);

// Problem 1: initializeStrings (5 points)
// Traverse the 2D array of characters variable 'strings' (input from user in main() ) and set all characters in each
// array to a null terminator so that there is a 4 row and 35 column 2D array full of null terminators.
// The null terminator is represented by the character value '\0' and is used to denote the end of a string.
// This may come in use later in the program to know the end of string.
void initializeStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{

}

// Problem 2: printStrings (5 points)
// Traverse the 2D character array "strings" and print each of the contained strings.
// See the example outputs provided in the word document. Your output should match the example outputs.
void printStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{

}

// Problem 3: reverseString (5 points)
// Reverse each string of strings[][].
// Consider one string at a time and reverse the characters. For instance, "hi hello" should reverse to "olleh ih".
void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <string.h>

#pragma warning(disable : 4996) // compiler directive for Visual Studio only

// Read before you start:
// You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully.
// All instructions are given above the required functions, please read them and follow them carefully.
// You shoud not modify the function return types or parameters.
// You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer.

// Global Macro Values. They are used to define the size of 2D array of characters
#define NUM_STRINGS 4
#define STRING_LENGTH 50

// Forward Declarations
void initializeStrings(char[NUM_STRINGS][STRING_LENGTH]);
void printStrings(char[NUM_STRINGS][STRING_LENGTH]);
void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH]);
void encryptStrings(char[NUM_STRINGS][STRING_LENGTH], int);
void decryptStrings(char[NUM_STRINGS][STRING_LENGTH], int);
int splitAndPrintSentences(char s[NUM_STRINGS*STRING_LENGTH]);
void inputMatrix(int matrixA[3][3]);
void determinant(int matrixA[3][3]);

// Problem 1: initializeStrings (5 points)
// Traverse the 2D array of characters variable 'strings' (input from user in main() ) and set all characters in each
// array to a null terminator so that there is a 4 row and 35 column 2D array full of null terminators.
// The null terminator is represented by the character value '\0' and is used to denote the end of a string.
// This may come in use later in the program to know the end of string.
void initializeStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
   for(int i=0;i<NUM_STRINGS;i++){
       strings[i][0]='\0';
   }
}

// Problem 2: printStrings (5 points)
// Traverse the 2D character array "strings" and print each of the contained strings.
// See the example outputs provided in the word document. Your output should match the example outputs.
void printStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
   for(int i=0;i<NUM_STRINGS;i++){
       for(int j=0;strings[i][j]!='\0' && j<STRING_LENGTH;j++){
           printf("%c",strings[i][j]);
       }
       printf("\n");
   }
}

// Problem 3: reverseString (5 points)
// Reverse each string of strings[][].
// Consider one string at a time and reverse the characters. For instance, "hi hello" should reverse to "olleh ih".
void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
   char str[STRING_LENGTH];
  
   for(int i=0;i<NUM_STRINGS;i++){
       int c=0;
      
      
       for(int j=0;strings[i][j]!='\0' && j<STRING_LENGTH;j++){
           str[j]=strings[i][j];
           c++;
       }
      
       for(int j=c-1;j>=0;j--){
           strings[i][c-j-1]=str[j];
       }
       strings[i][c]='\0';
  
   }  
}

int main(){
  
   char strngLst[NUM_STRINGS][STRING_LENGTH];
   initializeStrings(strngLst);
  
   strcpy(strngLst[0],"Hello , It is Me");
   strcpy(strngLst[1],"This is good");
   strcpy(strngLst[2],"I have a knowldge in programming");
   strcpy(strngLst[3],"Nice Day!");
  
  
   printf("Print Strings:-\n\n");
   printStrings(strngLst);
  
   printf("\n\nPrint Reverse Strings:-\n\n");
   reverseStrings(strngLst);
   printStrings(strngLst);
  
   return(0);
}

Add a comment
Know the answer?
Add Answer to:
Please help me for this homework problem, thanks!! Instruction:(use visual studio or gcc) Code and Problem:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT