The third homework of the second semester

1

1. Enter the English name of the month

char *getmonth(int n)
{
    char *a[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
    int i;
    for(i=0;i<=12;i++)
    {
       if(i==0)
       
       {
        continue;
       }else if (i==n)
       {
        return a[i-1];
       }
    }
    if(n<=0||n>=13)
    {
        return NULL;
    }
}

Ideas
According to the input number, output the month
without error
2. Find the week

int getindex( char *s )
{
    char *a[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday",};
    int i,n=0;
    for(i=0;i<7;i++)
    {
        if(strcmp(s,a[i])==0)
        {
            return i; 
        }
    }
    if(n<=0||n>=7)
    {
        return -1;
    }
 } 

Ideas
Output numbers according to the input week
without error
3. Calculate the longest string length

int max_len( char *s[], int n )
{
int max=0,j=0,long=0;
for(j=0;*(s+j)!='\0';j++)
{
    long=strlong(*(s+j));
    if(max<long)
    {
        max=long;
    }
}
return max;
}

Ideas
Compare the length of the input string and output the number of the longest string
No problem
4. Specify the position to output the string

char *match( char *s, char ch1, char ch2 )
{
int i=0,j=0;  
char *p=NULL;    
for(i=0;*(s+i)!='\0';i++)
{  
    if(s[i]==ch1)
    {  
        p=&s[i];  
        for(j=i;*(s+j)!='\0';j++)
        {  
            if(s[j]!=ch2)
            {  
                printf("%c", s[j]);  
            }  
            if(s[j]==ch2)
            {  
                printf("%c\n", s[j]);  
                return p;  
            }     
        }  
        printf("\n");  
        return p;  
    }  
}
if(s[i] == '\0')
p = &s[i];
printf("\n");  
return p; 
}

No problem
5. Odd-valued node list

struct ListNode *readlist()
{
struct ListNode *p=NULL,*tail=NULL,*head=NULL;
int data=0,count=0;
p=tail=(struct ListNode*)malloc(sizeof(struct ListNode));
scanf("%d",&data);
while(data!=-1)
{
    p->data=data;
    p->next=NULL;
    count++;
    if(count==1)
    {
        head=p;
    }else
    {
        tail->next=p;
        tail=p;
    }
    p=(struct ListNode*)malloc(sizeof(struct ListNode));
    scanf("%d",&data);
}
return head;
}
struct ListNode *getodd( struct ListNode **L )
{
struct ListNode *i=NULL,*head1=NULL,*head2=NULL,*m=NULL,*n=NULL;
i=*L;
head1=(struct ListNode*)malloc(sizeof(struct ListNode));
head2=(struct ListNode*)malloc(sizeof(struct ListNode));
head1->next=NULL;
head2->next=NULL;
m=head1;
n=head2;
while(i)
{
    if(i->data%2!=0)
    {
        m->next=i;
        m=i;
    }else
    {
        n->next=i;
        n=i;
    }
    i=i->next;
}
m->next=NULL;
n->next=NULL;
*L=head2->next;
return head1->next;
}

No question
5.6 questions will not

2. Learning summary and progress

1. Summarize the knowledge points learned in the past two weeks and answer the following questions? (Express your understanding in your own words, there are no points for copying and pasting online) (5 points)
(1) How do you understand pointer arrays and how does it relate to pointers and arrays? Why can you operate on arrays of pointers with secondary pointers?
An array of pointers is an array of pointers integrated.
(2) Change any subject of the third PTA assignment (1) of C advanced to use the second-level pointer to operate on the pointer array.

 (3)用指针数组处理多个字符串有何优势?可以直接输入多个字符串给未初始化的指针数组吗?为什么?
  用指针数组处理多个字符串比较快捷简便,不可以。

2. git
address

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324655469&siteId=291194637