File:  [CSRG BSD Unix] / 42BSD / usr.lib / learn / C / L31.1a
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:54 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD42
BSD 4.2

#print
Write a function named "rev(s)" which reverses
the string "s" in place. Name the file that contains
the function "rev.c".
When you're satisfied, type "ready".
#once #create Ref
cbax0987654321
#once #create tzaqc.c
main(){
	char *s1, *s2, *s3, *s4;
	s1 = "abc";
	s2 = "x";
	s3 = "";
	s4 = "1234567890";
	rev(s1);
	rev(s2);
	rev(s3);
	rev(s4);
	printf(s1);
	printf(s2);
	printf(s3);
	printf(s4);
	printf("\n");
}
#user
cc tzaqc.c rev.o
a.out >value
#cmp value Ref
#succeed
/* One way:*/

rev (s)
char *s;
{
	char *p;
	int t;
	
	for (p=s; *p; p++)
		;
	for (p--; p > s; p--, s++) {
		t = *p;
		*p = *s;
		*s = t;
	}
}
#log
#next
32.1a 10

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.