Home>
I want to determine if the last character is a specific character.
Its specific character is ".".
As you can see from the contents of the assert in the source code, the end of the address is "23." and the address notation is incorrect, so I want to make this an error.
But
if (strstr (src, "23.")) {
return (0);
Only the source code like
The created source code works like inet_pton.
I would appreciate your help.
Thank you in advance.
#include
#include
#include<stdio.h>
#include<string.h>
int inet_pton (const char * src, void * dst) {
// variable declaration
int suuti1, suuti2, suuti3, suuti4;
// union type definition
union number {
uint32_t number1;
uint8_t number2 [4];
};
// Declaring union variable names
union number No;
// Convert the string of src to a numeric value and determine if there are four
if (sscanf (src, "% d.% d.% d.% d",&suuti1,&suuti2,&suuti3,&suuti4)! = 4) {
return (0);
}
// Store the value converted to numeric value in a variable
No.number2 [0] = suuti1;
No.number2 [1] = suuti2;
No.number2 [2] = suuti3;
No.number2 [3] = suuti4;
// copy number1 memory to dst
memcpy (dst,&No.number1, 4);
return (1);
}
int main () {
int result;
struct in_addr in_addr;
result = inet_pton ("130.0.7.23",&in_addr);
assert (result == 1&&in_addr.s_addr == ((23<<24) | (7<<16) | (0<<8) | 130));
result = inet_pton ("130.0.7.23.",&in_addr);
assert (result == 0);
return (0);
}
-
Answer # 1
-
Answer # 2
This function gets the last character
How about this?char right (char * str) { int len = strlen (str); return 0
Related articles
- i want to determine if the character string is a number, but no result is output
- about the character string search program in c language
- python 3x list distinguish character at specific position
- i want to find the length of a character string using a pointer
- measure the length of the character string using the pointer (second time)
- i want to enter a character string that includes a line break
- can store only character strings of a size much smaller than the size secured by malloc
- c language: i want to copy a character to the string literal passed as an argument
- c language stack i want to make one set of character strings into one stack
- c language character string display
- c language: i want to select and sort "double-byte" character strings stored in a two-dimensional array
- inversion of character string using c language pointer
- the character array cannot be rearranged
- a method to read a character string from a file in c language and digitize a specific part
- c++ - i want to receive a specific reply when the character input using the self-made character string comparison function match
- c++ - i want to decompose an input character string using an array and to reply when a specific word in it is matched
- about the character string stored immediately after the c language command line argument
- store one character array from three character strings in sequence, one character array
- i want to convert an int number to a 4 character char
- i want to convert the char type array to a character code and make it an int type array
Trends
The last character should be taken to == '.'.
The string length l can be determined by using strlen, and src [l] is the terminal character, so the previous character is used for comparison.
If you want to make sure it ends with astring, write! strcmp (src + n, "hoge").
You need to calculate in advance where a particular string can start.