'how could I find and extract a punctuation from a word of a paragraph text file?

int main()
{
    FILE *fO;

    fO = fopen("random.txt", "r");

    size_t size = 0;
    int len = 0;

    // initialize it for the getline() and strtok()
    char *line = NULL;

    // loop through the file
    node *head = NULL;

    while (getline(&line, &size, fO) != -1) {
        // strip newline
        line[strcspn(line,"\n")] = 0;

        char *word = strtok(line," ");
        char *mark;
    
        while (word != NULL){
            word = strtok(NULL," ");
             
            //why would this part make mark == 44?
            if(ispunct(word[strlen(word)-1]) != 0){
                int w = word[strlen(word)-1];
                itoa(w, mark, 10);
                printf("%s mark\n", mark);
                //i was hoping that it would be punctuation of type const *char
            }
        }
    }

    //free at end
    free(line);

the file is like(for eg):

lorem ipsum,
dolor.
sit amet con,
sec it.

the file has unpredictable numbers of words on each line. I thought I was getting a character with mark = word[strlen(word)-1]. I expected to get a comma or period. Does anyone know why it ended up as an integer of 44?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source