I need to send the data to the server in a manner like 00 12 34 00 00 54 when I am doing a strcat of 00 to 1243 or strcat of 1234 to 000054 it's not concatenating 00 to string and the result is 1234 only. I know strcat treats 00 as a terminating null character that's why it is considering 00 as terminator.I have tried with the memcpy also but then in the server side 00 is coming as 3030. How can I make my program to treat 00 as the part of the array not as the terminating null character or to treat 00 as it is,not the ascii value as 30.
khushboo gupta
Posts
-
strcat_memcpy -
iso_8583 messageI am using the below code for packing the data in iso 8583 format 00 2E 60 01 23 06 00 08 00 20 20 01 00 00 c0 00 00 92 00 00 00 00 12 01 23 48 30 30 30 30 30 30 39 53 31 30 30 30 30 30 30 30 30 30 30 30 30 35
#include #include #include #include #include #include char cHexDigit\_to\_Nibble1(unsigned char c) { if(!isxdigit(c)) return (0); if(isdigit(c)) return (c - '0'); c = toupper(c); return (c - 55); } void vAscii2BCD(unsigned char \*pucSrc, unsigned char \*pucDst, int inSize) { for (; inSize > 0; inSize -= 2, pucDst++) { if(!memcmp(pucSrc, "3D", 2)) { pucSrc += 2; \*pucDst = '='; } else { \*pucDst = cHexDigit\_to\_Nibble1(\*pucSrc++) << 4; \*pucDst |= cHexDigit\_to\_Nibble1(\*pucSrc++); } } printf("data is %s\\n\\n",pucDst); } int main() { int sock\_desc, status; struct sockaddr\_in client; struct addrinfo hints; WSADATA Data; int bytesSent; int bytesRecv = SOCKET\_ERROR; unsigned char \*pucSrc = (unsigned char\*) malloc (100) ; unsigned char \*pucDst = (unsigned char\*) malloc (256) ; memset(pucSrc,0,256); memset(pucDst,0,256); vAscii2BCD((unsigned char\*)"00" ,pucDst, 1) ;// strcpy((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); vAscii2BCD((unsigned char\*)"2E" ,pucDst, 1) ;// //vAscii2BCD((unsigned char\*)"002E" ,pucDst, 4) ;// strcat((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"60012306 " ,pucDst, 12) ;// vAscii2BCD((unsigned char\*)"6001230600" ,pucDst, 5) ;// strcat((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)" 8 " ,pucDst, 4) ;//48564848 vAscii2BCD((unsigned char\*)"0800" ,pucDst, 2) ;//48564848 strcat((char\*)pucSrc,(char\*)pucDst); memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"2020010000C00000" ,pucDst, 16) ; vAscii2BCD((unsigned char\*)"2020010000" ,pucDst, 5) ; strcat((char\*)pucSrc,(char\*)pucDst); memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"2020010000C00000" ,pucDst, 16) ; vAscii2BCD((unsigned char\*)"C00000" ,pucDst, 3) ; strcat((char\*)pucSrc,(char\*)pucDst); memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"92" ,pucDst, 2) ;//575048484848 vAscii2BCD((unsigned char\*)"920000" ,pucDst, 3) ; strcat((char\*)pucSrc,(char\*)pucDst); //strcat((char\*)pucSrc,"00000000") ; printf("si
-
iso_8583 messageHello Sir, I really did not understand what "please edit the above entry" means. Can you pls tell me.. Do I need to edit something in the code or is this not the write way to post the code? Thanks
-
iso_8583 messagePlease check #include #include #include #include #include #include void Print_Debug(char *str) { printf("%s", str); ///change this prtES with your print API. } void Print_HexDump(char *Title, unsigned char * ucBuf, unsigned int uiSize) { unsigned int uiLoop; unsigned int uiChars = 0; char buffer[100]; if(uiSize == 0) return; Print_Debug(Title); memset(buffer, 0, 40); memset(buffer, '-', 39); Print_Debug(buffer); memset(buffer, ' ', 39); for (uiLoop = 0; uiLoop < uiSize; uiLoop++) { sprintf(&buffer[(uiChars * 3)], "%02X", ucBuf[uiLoop]); buffer[2 + (uiChars * 3)] = ' '; buffer[30 + uiChars] = ((ucBuf[uiLoop] > 32) && (ucBuf[uiLoop] < 125)) ? ucBuf[uiLoop] : '.'; uiChars++; if((uiChars == 10) || ((uiLoop + 1) == uiSize)) { buffer[29] = '|'; // column separater buffer[30 + uiChars] = 0; // null terminate string Print_Debug(buffer); memset(buffer, ' ', 40); uiChars = 0; } } memset(buffer, '-', 39); Print_Debug(buffer); } char cHexDigit_to_Nibble1(unsigned char c) { //if((!isxdigit(c)) || (c != 0x3D)) if(!isxdigit(c)) return (0); if(isdigit(c)) return (c - '0'); c = toupper(c); // adjust hexadecimal 'A' to 0x0A return (c - 55); } void vAscii2BCD(unsigned char *pucSrc, unsigned char *pucDst, int inSize) { for (; inSize > 0; inSize -= 2, pucDst++) { if(!memcmp(pucSrc, "3D", 2)) { pucSrc += 2; *pucDst = '='; } else { *pucDst = cHexDigit_to_Nibble1(*pucSrc++) << 4; *pucDst |= cHexDigit_to_Nibble1(*pucSrc++); } } printf("data is %s\n\n",pucDst); } //////////////////////////////////NUMERIC TO BCD///////////////////////////////// void numerictoBCD() { unsigned int uiValue = 920000; unsigned int uiResult = 0; while (uiValue > 0) { uiResult <<= 4; uiResult |= uiValue % 10; uiValue /= 10; } } unsigned long toPackedBcd (unsigned int val) { unsigned long bcdresult = 0; char i; for (i = 0; val; i++) { ((char*)&bcdresult)[i / 2] |= i & 1 ? (val % 10) << 4 : (val % 10) & 0xf; val /= 10; } return bcdresult; } int main() { int sock_desc, status; struct sockaddr_in client; struct addrinfo hints; WSADATA Data; int bytesSent; int bytesRecv = SOCKET_ERROR; //char sendbuf[32] = "Client: Sending data."; //char sendbuf[] = "002F600123060008002020010000c0000092000000001201234830303030303039533130303030303030303030303035"; //char sendbuf[] = "002F600123060008002020010000c000009200000000120123H0000009S10000000000
-
iso_8583 messageThe code which i am Using for creating the Packet is
#include
#include
#include
#include
#include
#includechar cHexDigit_to_Nibble1(unsigned char c)
{//if((!isxdigit(c)) || (c != 0x3D)) if(!isxdigit(c)) return (0); if(isdigit(c)) return (c - '0'); c = toupper(c); // adjust hexadecimal 'A' to 0x0A return (c - 55);
}
void vAscii2BCD(unsigned char *pucSrc, unsigned char *pucDst, int inSize)
{for (; inSize > 0; inSize -= 2, pucDst++) { if(!memcmp(pucSrc, "3D", 2)) { pucSrc += 2; \*pucDst = '='; } else { \*pucDst = cHexDigit\_to\_Nibble1(\*pucSrc++) << 4; \*pucDst |= cHexDigit\_to\_Nibble1(\*pucSrc++); } } printf("data is %s\\n\\n",pucDst);
}
int main()
{
int sock_desc, status;
struct sockaddr_in client;
struct addrinfo hints;
WSADATA Data;int bytesSent; int bytesRecv = SOCKET\_ERROR; //char sendbuf\[32\] = "Client: Sending data."; //char sendbuf\[\] = "002F600123060008002020010000c0000092000000001201234830303030303039533130303030303030303030303035"; //char sendbuf\[\] = "002F600123060008002020010000c000009200000000120123H0000009S10000000000005"; //char sendbuf\[\] = "0111011110000000010000110110100000110010010101110111000000110010100000001001011000010011011101000101010101110011000010001000000000000000000101000110000000000000000000011000000100110101H0000009S10000000000005"; char recvbuf\[256\] = ""; unsigned char \*pucSrc = (unsigned char\*) malloc (100) ; unsigned char \*pucDst = (unsigned char\*) malloc (256) ; //unsigned char \*Output\_Buff = (unsigned char\*) malloc (20) ; int inSize = 12 ; //memset(Output\_Buff,0,20) ; memset(pucSrc,0,256); memset(pucDst,0,256); vAscii2BCD((unsigned char\*)"00" ,pucDst, 1) ;// strcpy((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); vAscii2BCD((unsigned char\*)"2E" ,pucDst, 1) ;// //vAscii2BCD((unsigned char\*)"002E" ,pucDst, 4) ;// strcat((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"60012306 " ,pucDst, 12) ;// vAscii2BCD((unsigned char\*)"6001230600" ,pucDst, 5) ;// strcat((char\*)pucSrc,(char\*)pucDst) ; memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)" 8 " ,pucDst, 4) ;//48564848 vAscii2BCD((unsigned char\*)"0800" ,pucDst, 2) ;//48564848 strcat((char\*)pucSrc,(char\*)pucDst); memset(pucDst,0,256); //vAscii2BCD((unsigned char\*)"2020010000C0
-
iso_8583 messageI have sent the packet through tcp socket. when i was analyzing the packet through wireshark i was getting the packet in the server side like below : 2E 60 01 23 06 08 20 20 01 c0 00 .5 .#.... ..... 92 12 01 23 48 30 30 30 30 30 30 ...#H000009 39 53 31 30 30 30 30 30 30 30 30 30 30 30 30 35 9S10000000000005 while my actual packet is 00 2E 60 01 23 06 00 08 00 20 20 01 00 00 c0 00 .5 .#.... ..... 00 92 00 00 00 00 12 01 23 48 30 30 30 30 30 30 ........#H000009 39 53 31 30 30 30 30 30 30 30 30 30 30 30 30 35 9S10000000000005 Why all 00 bytes are not getting sent..Can anybody tell me. Please Help !!!!!
-
iso_8583 messageDear sir, I have given a doc of logon request which should be formatted like given below - 00 2E 60 01 23 06 00 08 00 20 20 01 00 00 c0 00 .5 .#.... ..... 00 92 00 00 00 00 12 01 23 48 30 30 30 30 30 30 ........#H000009 39 53 31 30 30 30 30 30 30 30 30 30 30 30 30 35 9S10000000000005 when i extracted bit fields from bit map i got the fields 3,11,24,41,42 in which field 3 and 11 are in N6 format, field 24 is in N3 format and field 41,42 are in ANS format.. I have gone through many reference sites of iso 8583 message format but i did not how can send the data.. whether i should convert the fields which are in N6 to BCD. whether i will have to send bit field as it is or i need to change it also in BCD.. How to send..pls help
-
utf to ascii conversionHello Sir, The solution which you have given is working fine for me in windows machine But now I need to implement the same thing (utf-8 to ascii conversion) in a POS terminal which neither has 'locale.h' nor _wcstombs_s_l in the stdlib. The POS terminal has linux kernal.My quries are : 1)Instead of using the function _wcstombs_s_l and create_locale can I replace it with the function definition itself. 2)If I can then please if possible provide me the link where I can find the proper definition of these two functions. 3)If i can not then is there any other way to implement utf8 to ascii conversion. Please help. Thanks
-
utf to ascii conversionThanks Sir for your reply. It solved my problem.
-
utf to ascii conversionThank you so much sir It solved my problem.
-
utf to ascii conversionHi sir, Can u please suggest me then how can i convert Arabic characters stored in utf-8 format in database to ascii characters in c. Is there any built-in function through which i can perform conversion from utf-8 to ascii. Thanks
-
utf to ascii conversionHi, Can anybody suggest me how can i convert a string from utf8 (like wchar_t toTranscode[] = L"ناعسالاخخ";) format to ascii (like äÇÚÓÇáÇÎÎ).. I have tried with the following code ..but when i am trying to print char array pToFill it is blank.
#include "stdio.h"
#include <string.h>
#include "stdlib.h"
#define _CRT_SECURE_NO_WARNINGSint main()
{
FILE *p = NULL;
size_t len = 0;
unsigned int convertedChars = 0;int ret; wchar\_t toTranscode\[\] = L"ناعسالاخخ"; //wchar\_t toTranscode\[\] = L"hello"; unsigned int wLent = wcslen((const wchar\_t\*)toTranscode); //------------------------------------------------------ // a UTF-8 character can have maximum 6 bytes //------------------------------------------------------ int maxCharLen = 6\*wLent; wchar\_t\* pWideCharBuf; char\* pToFill; unsigned int i; //-------------------------------------------------------------- // alloc memory for variables. //-------------------------------------------------------------- pWideCharBuf = (wchar\_t\*)malloc(wLent+1); pToFill = (char\*)malloc(maxCharLen+1); for (i = 0; i < wLent; ++i) pWideCharBuf\[i\] = toTranscode\[i\]; pWideCharBuf\[wLent\] = 0x00; memset (pToFill, 0, maxCharLen+1);
// convert the string
//ret = wcstombs(pToFill, pWideCharBuf, maxCharLen); ret = wcstombs\_s(&convertedChars, pToFill, maxCharLen, pWideCharBuf, maxCharLen); //ret = wcstombs\_s(&convertedChars, pToFill, maxCharLen, pWideCharBuf, \_TRUNCATE); printf("ret is %d\\n", ret); printf("the ascii char is = %s\\n", pToFill); printf("to test\\n"); p = fopen("hello.txt", "w"); if (p== NULL) { printf("Error in opening a file.."); }
len = strlen(pToFill);
fwrite(pToFill, len, 1, p);
fclose(p);
printf("\nWritten Successfuly in the file.\n");// pToFill contains the string //------------------------------------------------------- // clean-up //------------------------------------------------------- //lete \[\] pWideCharBuf ; // don't forget to //delete \[\] pToFill ; return 0;
}
please help