Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write declarations for each of the following variables: a. amounts is an arra

ID: 3665926 • Letter: 1

Question

1. Write declarations for each of the following variables:

a. amounts is an array of 8 longs

b. net_inc is an array of 12 floats

c. daily_tot is an array of 12 arrays of 31 ints

d. names is an array of 12 pointers to arrays of 50 char

2. Given that pi and pj are pointers to int, and ii and ij are ints, which of the following expressions are valid?

a. pi + ii

b. pi + pj

c. pi++

d. pi - ii

e. pi - pj

3. Write your own definition of strcpy() using array notation. (This means write the code that implements the function. Refer to Appendix B for the strcpy() function prototype.)

4. Write your own definition of strcpy() using pointer notation.

5. Write a declaration, including arguments and result, for a two-dimensional version of strlen, that is, a function that receives an array of pointers to char and an array of size_t integers, and an int that specifies the number of elements in each array. (You don't need to write the actual function.)

6. Write a function void shift(char *) that looks at the first character of its argument and converts the other characters, to be the same case, that is, if the first character is uppercase, it shifts the rest to uppercase; if the first character is lowercase, it shifts the rest to lowercase, and otherwise, it does nothing.

Explanation / Answer

1.
a. long amounts[8];
b. float net_inc[12];
c. int daily_tot[12][31];
d. char names[12][50];

2.
a. pi + ii -> valid
b. pi + pj -> Invalid
c. pi++ -> valid
d. pi-ii ->valid
e. pi-pj -> valid

3.

void strcpy1(char dest[], const char source[]) {
int i = 0;
while (1) {
dest[i] = source[i];
if (dest[i] == '') break;
i++;
   }
}

4.

char *strcpy(char *strDest, const char *strSrc)
{
assert(strDest!=NULL && strSrc!=NULL);
char *temp = strDest;
while(*strDest++ = *strSrc++); // or while((*strDest++=*strSrc++) != '');
return temp;
}

5.
int strlen(char *array[], int size, int number );
  
6.
void shift(char *str) {
  
   }
  
  
   void shift(char *string){   
       int i;
       char first = string[0];
       bool lowercase = false, uppercase = false
       if (first >= 'A' && first <= 'Z')
               uppercase = true;
       else
               lowercase = true;
          
       for (i=1;sting[i] !='';i++){
           if (uppercase){
               string[i]= toupper(string[i]);
           }else{
               string[i] = tolower(string[i]);
               }
       }
}