㈠ c語言編程問題
voiddel(char*s,intn,intlen)
{char*p,*q;
for(p=s;*p;p++);
if(n<0||n+len>p-s){printf("error");return0;}
p=s+n;
q=p+len;
for(;*p=*q;);
}
㈡ c語言編程作業 函數strdel,求指導!!
請問介面是什麼
函數的原型是什麼
#include <stdio.h>
void strdel(char*s,char del)
{
int i,j;
for(i=0,j=0;s[i];i++)
{
if(s[i]!=del)
s[j++] = s[i];
}
s[j] = 0;
}
int main()
{
char s[1000];
char del;
while(gets(s)!=NULL)
{
scanf("%c",&del);
strdel(s,del);
printf("%s\n",s);
}
}
㈢ 【C語言編程】寫一個函數del,刪除動態鏈表中指定的結點
#include <stdio.h>
#include <malloc.h>
#include <conio.h>
typedef struct node //定義節點
{
int value;
struct node* next;
}note;
note* head = NULL;
void del (note** head, int k)//刪除鏈表
{
note* pp;
note* pt;
note* pq;
pp = *head;
if ((*head)->value == k)//如果頭結點的值等於k,刪除頭結點
{
*head = (*head)->next;
return;
}
while(pp->value != k)
{
pt = pp;
pq = pp->next;
pp = pq;
}
pt->next = pp->next;//刪除結點
}
void insert(note** head, int q)//建立鏈表
{
note* pp;
note* pt;
note* p = (note*)malloc(sizeof(note));
p->value = q;
p->next = NULL;
pp = *head;
if (*head==NULL)
{
*head=p;
return;
}
while(pp->next!=NULL)
{
pt = pp->next;
pp = pt;
}
pp->next = p;
}
void print(note* head)//列印鏈表
{
note* pp;
while(head!=NULL)
{
printf("%d ", head->value);
pp = head->next;
head = pp;
}
}
int main()
{
int i;
int n,k,value;
scanf("%d %d",&n, &k);
for(i=0; i<n; i++)
{
scanf("%d", &value);
insert(&head, value); //把head的地址傳過去
}
del(&head, k);
print(head);
getch();//隨意按個鍵退出界面
return 0;
}
㈣ C語言問題 實現在字元串的內部刪除字元串的函數del。
#include<stdio.h>
voiddel(char*s,intn,intlen)
{char*p;
s+=n;
for(p=s+len;*s++=*p++;);
}
intmain()
{chars[]="apple";
if(s==NULL||n<0)
{printf("error");
return0;
}
del(s,2,2);
puts(s);
return0;
}
㈤ C語言編程 編寫一個函數delchar(char s[],char ch) 將數組s存放的字元串中
voiddelchar(chars[],charch)
{
char*pre=s;
char*aft=s;
while(*aft)
{
if(*aft!=ch){
*pre=*aft;
++pre;
++aft;
}else{
++aft;
}
}
*pre='