I made this program that takes a name and prints the initials, but...it takes the name in the command line. How can I use get_string() to create an array of strings instead of argv, and argc wich is very unorthodox and sloppy, so I can prompt the user to give me her/his name. Thank you.
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(int argc, string argv[])
{
//How do I use Get_string() so I don't have to use argv and argc??
//iterate over strings on the vector (words)
for (int i = 0; i < argc; i++)
{
//prints the 0 character of each string, use "toupper" to convert into capital letters
printf("%c", toupper(argv[i][0]));
}
printf("\n");
}
UPDATE
Hi! I'm still stuck but I think I'm in the right path. I substitute argc for an int that counts the chars, and argv will be the get_int() string, but I'm afraid I am missing something since I don't know how to make an array of words, that stores each of the words of the user input as diferents elements of the array. This is what I got so far, and the error is
error: subscripted value is not an array, pointer, or vector
printf("%c", toupper(name[i][0]));
This is the code that I have:
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
printf("Enter your name and last name:\n");
string name = get_string(); //this will be like argv?
int c = strlen(name); //this will be like argc
//iterate over characters
for (int i = 0; i < c; i++)
{
//prints the 0 of i, that means the 0 char of each word, use "toupper" to convert into capital letters
printf("%c", toupper(name[i][0]));
}
printf("\n");
}