|
|
1.1 ! root 1: #print ! 2: Write a subroutine named "locn(s,c)" which expects two ! 3: arguments: the first is a pointer to characters 's' which ! 4: points to a null-terminated string, and the second ! 5: is a character 'c' which is to be searched for in the ! 6: string 's'. If the character 'c' does not ! 7: appear in the string return 0; otherwise return a pointer ! 8: to the position of 'c' in the string. Name the program "locn.c"; ! 9: as usual, compile and test it and then type "ready". ! 10: #once #create Ref ! 11: 0 ! 12: 19 ! 13: 0 ! 14: 25 ! 15: 0 ! 16: #once #create tzaqc.c ! 17: char *alpha "abcdefghijklmnopqrstuvwxyz"; ! 18: main() ! 19: { ! 20: extern char *locn(); ! 21: printf("%d\n", locn(alpha, '+')); ! 22: printf("%d\n",locn(alpha, 't')-alpha); ! 23: printf("%d\n",locn(alpha, 'a')-alpha); ! 24: printf("%d\n",locn(alpha, 'z')-alpha); ! 25: printf("%d\n",locn("", 'z')); ! 26: } ! 27: #user ! 28: cc tzaqc.c locn.o ! 29: a.out >value ! 30: #cmp value Ref ! 31: #succeed ! 32: /* Try this: */ ! 33: ! 34: char * ! 35: locn (s, c) ! 36: char *s; ! 37: { ! 38: for( ; *s; s++) ! 39: if (*s == c) ! 40: return(s); ! 41: return(0); ! 42: } ! 43: #log ! 44: #next ! 45: 31.1a 10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.