#include <stdio.h>
int do_sth (char *s);
main(){
char arr [] = "We are the World";
printf ("%d\n", do_sth(arr));
}
int do_sth(char *s)
{
char *p = s;
while ( *s++ != ‘\0’ )
return s - p;
}
What does function do_sth intend to do?
What is the output of the program?
, In the linked list implementations in labtest 2 and lab, to make the code easier, we declare the head to
be a global variable. An alternative way is to declare head as a local variable and pass it as a function
parameter.
Write a function return_type insertFirst(struct node* head, char d) which inserts in
the beginning of the list a new node with data d. You need to define the return type of the function. You
also needs to call this function to insert nodes with data ‘A’and ‘E’ into the list.
#include <stdio.h>
struct node {
char data;
struct node *next;
};
/************* DO NOT ADD MORE GLOBAL VARIABLES *************/
/*Define your function below:*/
struct node * insertFirst (struct node * list_head, char d){
/***** ADD YOUR CODE HERE *****/
struct node * newP = malloc (sizeof(struct node));
newP -> data = d;
newP -> next = list_head;
list_head = newP;
return list_head;
}
main(){
struct node * head;
/* call your function (twice) to insert nodes of data ‘A’‘E’ into list */
head = insertFirst (head, ‘A’);
head = insertFirst (head, ‘E’);
}