i got a new problem i just need a way to start coding this but while searching for the 1's and 0's i need to also look for the word 'RTP' and the word 'RTP' is followed by a number. Any suggestions on how to do this because when i find RTP, the number after it determines how my times the 8 1's/0's are used (ie. if i find RTP4, then the 8 1's/0's are lets say 10101010 then i have to make it output 4 times;
10101010
10101010
10101010
10101010)
this is my code right now
Code:
int bit_to_ascii(const char core[ ], char data[ ]);
int main( ) {
char core2[256];
char data2[13];
int rc2;
printf("enter: ");
scanf("%256[^\n]", core2);
rc2 = bit_to_ascii(core2, data2);
return 0;
}
int bit_to_ascii(const char core[ ], char data[ ]) {
int i, rc = 0, j, inte[7], len, len2, m;
char binarray[8];
for(i=0, j=0; core[i] != '\0'; i++) {
switch(core[i]) {
case '1':
case '0':
if(j<8) {
binarray[j++] = core[i];
}
else {
binarray[j] = '\0';
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
printf("the binary array is: '%s' %d %d %d %d %d %d %d %d\n", binarray, inte[0], inte[1], inte[2], inte[3], inte[4], inte[5], inte[6], inte[7]);
j = 0; /* resets j to 0 after 8 1's or 0's have been found */
if(j<8) {
binarray[j++] = core[i];
} //end if
}//end else
}//end switch
}//end for loop
//for last set of 8 1's/0's
binarray[j] = '\0';
len = strlen(binarray); //finds lenght to determine how much zero's to add if lenght is less than 8
printf("%d\n", len);
if(len<8){
len2 = 8 - len;
m = len;
printf("%d\n", len2);
do {
binarray[m]='0';
m++;
}while (m != 8);
}
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
printf("the binary array is: '%s' %d %d %d %d %d %d %d %d\n", binarray, inte[0], inte[1], inte[2], inte[3], inte[4], inte[5], inte[6], inte[7]);
return rc;
}