Segmentation fault: could someone help me to understand my mistake?
Target: make a new string with only CAPS LETTERS.
Also, I am trying to identify letters I do not want by referring to the ASCII table, hopefully, that is the right approach.
CS50 IDE, going through CS50 course by Harvard
#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
// Points assigned to each letter of the alphabet
int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
// int compute_score(string word);
int put_down_caps_only(string word);
int main(void)
{
string word1 = get_string("Player 1: ");
string word1CapsOnly="";
char chr;
for(int i=0; i<strlen(word1);i++)
{
if(word1[i]<123&&word1[i]>96)
{
// use to upper function
// is lower would work here nicely
chr = toupper(word1[i]);
strncat(word1CapsOnly, &chr, 1);
}
else if(word1[i]<65 || word1[i]>122)
{
//ignore
}
else
{
//just add, upper alredy
strncat(word1CapsOnly, &word1[i], 1);
}
}
printf("%s", word1CapsOnly);
// int score1 = compute_score(word1);
// TODO: Print the winner
}
/* int compute_score(string word)
{
// TODO: Compute and return score for string
} */