.
This commit is contained in:
26
bac2/os/chap0/ex4.c
Normal file
26
bac2/os/chap0/ex4.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void delete(char string[], char target);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char test[] = "test test";
|
||||
printf("%s\n", test);
|
||||
delete(test, 'e');
|
||||
printf("%s\n", test);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void delete(char string[], char target){
|
||||
int i = 0, offset = 0;
|
||||
while(string[i] != '\0'){
|
||||
if(string[i+offset] == target){
|
||||
offset++;
|
||||
}
|
||||
string[i] = string[i+offset];
|
||||
i++;
|
||||
}
|
||||
string[i] = '\0';
|
||||
}
|
Reference in New Issue
Block a user