Waitrud Weber’s blog

things and reminders for memories

In linux about "m_compare":

 (20200828: )
We reproduced the function "a_compare".

We must understand segmentation error:
array_count is useful here.

Useful library in C should be used of any analyzer.
We can change File Pointer to the end and the middle flexible.
We must use it, which is one of futures of C and better than other languages.

In any OS, C still remained, even in Server.
At the most, computer has usually,

1. Memory
2. File system
3. Processing

So, in server, the program write logs as functions print messages.
After error, of, we can not maintain and repaire if we do not have the messages.

Code indicated in Java like Exception, In C we overcome the messages less useful.
One of them is putting "function starts." and "function ends." in their codes as position.

 

log files:
a_compare starts.
(EOF)

We could realise something happend error in the function "a_compare".

 

//
//
//
int a_compare (char* s1, char* s2 ) {
	int c, c1, c2;
	int i;
	char r1, r2;
	int result;
	int sep;

	printf("a_compare starts.\n");

	c1 = array_count(s1);
	c2 = array_count(s2);

	if ( c1 < c2 ) {
		c = c1;
		r2 = s2[c1];	
		s2[c1] = '\0';	
		sep = 0;
	} if ( c1 == c2 ) {
		c = c1;
		sep = 1;
	} else {
		c = c2;
		r1 = s1[c2];	
		s1[c2] = '\0';	
		sep = 2;
	}

	printf("a_compare|%s||%s| 003\n", s1, s2);

	result = m_compare( s1, s2 );



	switch ( sep ) {
	case 0:
		printf("case sep=0\n");
		s2[c] = r1;
		break;
	case 1:
		printf("case sep=1\n");
		break;
	case 2:
		printf("case sep=2\n");
		s1[c] = r2;
		break;
	default:
		break;
	}

	printf("a_compare ends.\n");
	return result;
}