Can some body please help me here. I am just lost.
#include <stdio.h>
#include<stdlib.h>
main (){
char mr[18],wmr[18];int imr = 0;char pcs[] = "H5146B2";char pi[]="210023610512918234";
printf("Id = %s, pcs = %s \n",pi,pcs);
imr = atoi((char *)(strncpy((char *)(mr),(char *)pi+7,2))) + 2000;
printf("Appende = %s and i value = %s and imr = %d\n",mr,mr,imr);
/*sprintf(mr,"%d",imr);*/
imr = atoi((char *)(strncpy((char *)(mr),(char *)pi+7,2))) + 2000;
printf("Appendf = %s and i value = %s and imr = %d\n",mr,pi+7,imr);
imr=atoi((char *)(strncpy((char *)(mr),pi+7,2)))+2000;
printf("Append2 = %s and i value = %d\n",mr,imr);
}
Output :
Id = 210023610512918234, pcs = H5146B2
Appende = 10 and i value = 10 and imr = 2010
Appendf = 10 and i value = 10512918234 and imr = 2010
Append2 = 10 and i value = 2010
As soon as I uncomment sprintf
Output :
Id = 210023610512918234, pcs = H5146B2
Appende = 10 and i value = 10 and imr = 2010
Appendf = 1010 and i value = 10512918234 and imr = 3010
Append2 = 1010 and i value = 3010
I was expecting the value of imr to be 2010.
Thanks in advance.
#include <stdio.h>
#include<stdlib.h>
main (){
char mr[18],wmr[18];int imr = 0;char pcs[] = "H5146B2";char pi[]="210023610512918234";
printf("Id = %s, pcs = %s \n",pi,pcs);
imr = atoi((char *)(strncpy((char *)(mr),(char *)pi+7,2))) + 2000;
printf("Appende = %s and i value = %s and imr = %d\n",mr,mr,imr);
/*sprintf(mr,"%d",imr);*/
imr = atoi((char *)(strncpy((char *)(mr),(char *)pi+7,2))) + 2000;
printf("Appendf = %s and i value = %s and imr = %d\n",mr,pi+7,imr);
imr=atoi((char *)(strncpy((char *)(mr),pi+7,2)))+2000;
printf("Append2 = %s and i value = %d\n",mr,imr);
}
Output :
Id = 210023610512918234, pcs = H5146B2
Appende = 10 and i value = 10 and imr = 2010
Appendf = 10 and i value = 10512918234 and imr = 2010
Append2 = 10 and i value = 2010
As soon as I uncomment sprintf
Output :
Id = 210023610512918234, pcs = H5146B2
Appende = 10 and i value = 10 and imr = 2010
Appendf = 1010 and i value = 10512918234 and imr = 3010
Append2 = 1010 and i value = 3010
I was expecting the value of imr to be 2010.
Thanks in advance.