strcmp(1): code clarification
This commit is contained in:
		
							parent
							
								
									efb3ce626d
								
							
						
					
					
						commit
						becb3bac4e
					
				@ -30,10 +30,11 @@ int main(int argc, char *argv[]){
 | 
			
		||||
		return EX_USAGE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in ref */
 | 
			
		||||
		/* iterate argc */
 | 
			
		||||
		for (size_t i = 2 /* ref cmp */; i < argc; ++argv[i], ++i) {
 | 
			
		||||
			/* this doesn't overrun because of nul termination */
 | 
			
		||||
	/* This compares the Nth character of arg[2] onward with argv[1]'s Nth
 | 
			
		||||
	 * character, rather than comparing each arg with argv[1] sequentially. */
 | 
			
		||||
	for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in argv[1] */
 | 
			
		||||
		for (size_t i = 2; i < argc; ++argv[i], ++i) { /* iterate &argv[2] */
 | 
			
		||||
			/* this never overruns because of nul termination */
 | 
			
		||||
			if (*argv[i-1] != *argv[i]) { return *argv[i-1] - *argv[i]; }
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user