50 date:2021.3.16
要点:
链表
详细代码如下:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
SLIST *creatlist(char *);
void outlist(SLIST *);
int fun( SLIST *h, char ch)
{ SLIST *p; int n=0;
p=h->next;
/**********found**********/
while(p!=NULL) //while循环判断是否到达链表结尾,链表结尾结点指针域是NULL
{ n++;
/**********found**********/
if (p->data==ch) return n;
else p=p->next;
}
return 0;
}
void main()
{ SLIST *head; int k; char ch;
char a[N]={'m','p','g','a','w','x','r','d'};
head=creatlist(a);
outlist(head);
printf("Enter a letter:");
scanf("%c",&ch);
/**********found**********/
k=fun(head,ch);
if (k==0) printf("\nNot found!\n");
else printf("The sequence number is : %d\n",k);
}
要点:
isspace() 函数功能: 检查字符串中是否有空格、跳格符(制表符)、换行符
详细代码如下:
#include <string.h>
#include <stdio.h>
#include <ctype.h>
void fun ( char *p)
{ int i,t; char c[80];
/************found************/
for (i = 0,t = 0; p[i] ; i++)
if(!isspace(*(p+i))) c[t++]=p[i];
/************found************/
c[t]='\0';
strcpy(p,c);
}
void main( )
{ char c,s[80];
int i=0;
printf("Input a string:");
c=getchar();
while(c!='#')
{ s[i]=c;i++;c=getchar(); }
s[i]='\0';
fun(s);
puts(s);
}
要点:
详细代码如下:
#include <stdio.h>
#include <string.h>
void fun ( char *ss )
{
int i,j=0;
// int n =strlen(ss);
for(i = 0; ss[i] !='\0'; i++)
{
if( (i%2 ==1) && ('a' <= ss[i] && ss[i]<= 'z' ))
{
ss[i] = ss[i]-32;//不可用ss[j++]来存储
}
}
//ss[j] = '\0';
}
void main( )
{ char tt[81] ;
void NONO ( );
printf( "\nPlease enter an string within 80 characters:\n" ); gets( tt );
printf( "\n\nAfter changing, the string\n \"%s\"", tt );
fun( tt );
printf( "\nbecomes\n \"%s\"\n", tt );
NONO ( );
}