commments for 6 and 7. 9 works, 8 does not
This commit is contained in:
50
Assignment 9/main.c
Normal file
50
Assignment 9/main.c
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Student: S.K. Soekhlal
|
||||
* Number: 4860632
|
||||
* Assignment: 4.8
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char str[1024];
|
||||
int slen, wlen, count, i, j;
|
||||
|
||||
void next(){
|
||||
while(isspace(str[i]) == 0 && ispunct(str[i] == 0 && str[i] != '\0'))
|
||||
i++;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
gets(str);
|
||||
slen = strlen(str);
|
||||
printf("%d\n", slen);
|
||||
wlen = strlen(argv[1]);
|
||||
printf("%d\n", wlen);
|
||||
for (i = 0; i < slen; i++){
|
||||
}
|
||||
i = j = count = 0;
|
||||
while(i < slen){
|
||||
if (str[i] == *argv[1]){
|
||||
for (j = 0; j < wlen; j++){
|
||||
if(str[i+j] != argv[1][j]){
|
||||
next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == wlen){
|
||||
if (isspace(str[i+j]) || ispunct(str[i+j]) || str[i+j] == '\0'){
|
||||
count++;
|
||||
i +=j;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
next();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
printf("%d\n", count);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user