Somehow only str2 is succesfully scanned and str1 is not printed
result : - str2:Code:printf("\n\n Please enter two times in this way xx.xx xx.xx now "); scanf("%s%s", str1, str2); printf("\n\n %s - %s:\n", str1, str2));
Somehow only str2 is succesfully scanned and str1 is not printed
result : - str2:Code:printf("\n\n Please enter two times in this way xx.xx xx.xx now "); scanf("%s%s", str1, str2); printf("\n\n %s - %s:\n", str1, str2));
This is incorrect. Assuming you type two separate strings (ie separated by spaces with no other punctuation), they are both picked up by scanf.
Note: I have assumed you have declared str1 and str2 as char arrays, or char pointers pointing to separate pieces of memory. If you have (for instance) pointed them at the same piece of memory, then that can also cause errors.
So should i have two separate scanf calls or is it possible with 1?, i tried writing scanf("%5s%5s", str1, str2); to no avail
What you have works; or if it doesn't work, the error is elsewhere. In other words this code:
correctly gives you two different strings:Code:#include<stdio.h> int main(void) { char str1[80], str2[80]; printf("\n\n Please enter two times in this way xx.xx xx.xx now "); scanf("%s%s", str1, str2); printf("\n\n %s - %s:\n", str1, str2); return 0; }
Code:C:\Users\tabstop\Desktop>temp Please enter two times in this way xx.xx xx.xx now 22.25 23.15 22.25 - 23.15: C:\Users\tabstop\Desktop>