[ create a new paste ] login | about

Link: http://codepad.org/SXKs4A0L    [ raw code | output | fork ]

nel - C, pasted on Oct 21:
/*

1. Passing to function stringCheck pointer to the first (input string) and second
(output string) strings.
2. Create 'unsigned char temp' to store current array-character value, for comparsion then.
3. Create counting variable for count equal (a==b,b==c and so) values
4. Fill the same array elements with 0, last with '-';
5. Fill (output string) array with edited string, but if(currChar==0), curChar++; ;-)
6. Print new (output) string.

*/

#include <stdio.h>
 
int stringCheck(char *in_str, char *out_str);

#define MAX 50 /* MAX = 50 */

 int main(void)
 {
     char in_str[MAX] = "abcdfgh";
     char out_str[MAX];

     stringCheck(in_str, out_str);
     
     printf("%s", out_str);
     printf("\n%s", in_str);
	 return 0;
 }

int stringCheck(char *in_str, char *out_str)
 {
	 // working variables declarations 
	 unsigned char temp;
	 unsigned int count = 0;

	 // let's compare ;-)
	 while(*in_str!='\0') {
		 temp = *in_str;

		 // IF TRUE
		 if(*(in_str+1)==(temp+1)) {
			 printf("for %c == %c: yes\n", *(in_str), (temp+1));
			 *in_str='\n';
		 }
		 
		 *in_str++;
		 count++; 
	 }

	 while(count--) { // while 'count' is positive (count>=0)
		 if(*in_str=='\n') *in_str--;
		 else *out_str = *in_str;
		 
		 *in_str--;
		 *out_str++;
	 }

         return 0;

	 //getch();
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
for a == b: yes
for b == c: yes
for c == d: yes
for f == g: yes
for g == h: yes




d

h


Create a new paste based on this one


Comments: