Question

A character array that was taken from received raw SMS format was {'+','C','M','T',' ','2','0','2','0','-','2','9','-','1','2'}. Create a program that will extract the date and store it in a character array with the following format {'M','M','/','D','D',

A character array that was taken from received raw SMS format was {'+','C','M','T',' ','2','0','2','0','-','2','9','-','1','2'}.  Create a program that will extract the date and store it in a character array with the following format {'M','M','/','D','D','/','Y','Y','Y','Y'}.   Use a function aside from main function that  returns a value.  See attached table in the instructions for additional requirement. Use "for loop" using C language.

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

#include<stdio.h>

#include<stdlib.h>


/*date function returns a char array of date format*/

char *  date(char * sms,int n){

    /*creating a char array of size 10*/

    char * date=(char*)malloc(10*sizeof(char));

    /*i stores index position of sms*/

    int i=0;

    /*index to store year in date array*/

    int yr=0;

    /*index to store year in date array*/

    int mon=0;

    /*index to store day in date array*/

    int day=0;

    /*while loop for iterating through each index*/

    while(i<15){

        /*if char is a number or - */

        if((sms[i]>='0'&&sms[i]<='9')||sms[i]=='-'){

            /*if i is less than 9*/

            if(i<9){

                /*store the year from sms in appropriate position in date*/

                date[6+yr]=sms[i];

                yr++;

            }

            /* if i is 9*/

            else if(i==9){

                /* insert / at index 5 in date*/

                date[5]='/';

            }

            /*if i >=10 and i< =11*/

            else if(i>=10 && i<=11){

                /*insert day from sms into date array*/

                date[3+day]=sms[i];

                day++;

            }

            /* if i is 12  */

            else if(i==12){

                /* insert / at index 2 in date*/

                date[2]='/';

            }

            else{

                /*insert month from sms into date array*/

                date[mon]=sms[i];

                mon++;

            }

        }

        i++;

    }

    return date;

};


int main(){

    /*Sms array*/

    char sms[15]={'+','C','M','T',' ','2','0','2','0','-','2','9','-','1','2'};

    /*invoking date function and storing the date array in date 1*/

    char * date1=date(sms,15);

    /* Printing date */

    printf("%s",date1);

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
A character array that was taken from received raw SMS format was {'+','C','M','T',' ','2','0','2','0','-','2','9','-','1','2'}. Create a program that will extract the date and store it in a character array with the following format {'M','M','/','D','D',
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
  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populat...

    Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populated with n random values. Write only the code to find the location of the maximum value in the array. Question 2 Follow these instructions in your Linux account: 1. Create a file called data.txt in the root folder in your account. 2. Create a new...

  • C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show...

    C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • C++ Programming - Design Process I need to create a flow chart based on the program...

    C++ Programming - Design Process I need to create a flow chart based on the program I have created. I am very inexperienced with creating this design and your help will be much appreciated. My program takes a string of random letters and puts them them order. Our teacher gave us specific functions to use. Here is the code: //list of all the header files #include <iomanip> #include <iostream> #include <algorithm> #include <string> using namespace std; //Here are the Function...

  • Write a program to create a game map. A game map is a 2D array of...

    Write a program to create a game map. A game map is a 2D array of regions, or tiles, of a world, as in the example of the figure to the right . For example, a tile with a value of 0 might represent water, 1 might represent land, 2 might represent a mountain and so forth. This map is represented as a class named CMap that has the properties: • A 2D array, having a height and width of...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • 1. Create a new class called ReversibleArray. 2. In the class header, add the code <T>...

    1. Create a new class called ReversibleArray. 2. In the class header, add the code <T> immediately to the right of the class name. 3. Give this class two private instance variables: T[] array and int count 4. Create a constructor which takes in one parameter of type T[] and assign that parameter's value into this.array. Set count as the length of the array. 5. Add a toString() method that outputs the array values in the format: elem0, elem1, elem2,...

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
ADVERTISEMENT