Wow Ive just discovered your channel! You're an amazing teacher!! So What about if my str is something like "123Abetc" How can I separate the int part from the char part to evaluate them separately? Ive read strtol can accomplish this but I haven't figured out how yet! Thank you very much!
Yes, you can use strtol to separate the two. Here's a code snippet: char str[] = "123ABetc"; char strPart[100]; char* endPtr; long int numPart = strtol(str, &endPtr, 10); // numPart will be 123 // Here endPtr will point to the first letter in the str string. printf("%s ", endPtr); // Would print just the string part from the original string strcpy(strPart, endPtr); // strPart will be "ABetc", this will save the remamining string to another location (in strPart) which you can freely modify At the end: numPart will have the value 123 strPart will have the value "ABetc" And thanks for the support, it is much appreciated!
Hey ! Thank you for the vids ! Can you show me how to make a header or a file , where I can have commonly used funtions stored , for example , to use them faster when I need them . So , just to include the header , in use whatever function I need .
YOU ARE A GENIOUS!!! been trying to find out how to validate numbers when a user inputs a no number value, this is simple and works just fine!!!
Bro, thanks for your channel!!! Now I will sucessed on algorithms in college. Keep with your great work
Greta video; great explanation. Much better than the man pages in UNIX. Cheers mate
Wow Ive just discovered your channel! You're an amazing teacher!!
So What about if my str is something like "123Abetc"
How can I separate the int part from the char part to evaluate them separately?
Ive read strtol can accomplish this but I haven't figured out how yet!
Thank you very much!
Yes, you can use strtol to separate the two. Here's a code snippet:
char str[] = "123ABetc";
char strPart[100];
char* endPtr;
long int numPart = strtol(str, &endPtr, 10); // numPart will be 123
// Here endPtr will point to the first letter in the str string.
printf("%s
", endPtr); // Would print just the string part from the original string
strcpy(strPart, endPtr); // strPart will be "ABetc", this will save the remamining string to another location (in strPart) which you can freely modify
At the end:
numPart will have the value 123
strPart will have the value "ABetc"
And thanks for the support, it is much appreciated!
thanks
Hey ! Thank you for the vids ! Can you show me how to make a header or a file , where I can have commonly used funtions stored , for example , to use them faster when I need them . So , just to include the header , in use whatever function I need .
Sure thing, I can make a video on that. Expect it next week.
Thank you for the video. What about real numbers how to validate 123.45 ?
Try using strtof or strtod: www.cplusplus.com/reference/cstdlib/strtod/
Basically the same as strtol but for real numbers