I normally watch the video and then switch to my editor program and rebuild it out of memory following my logic and the tools I just learned.
So I programmed it a little bit different and wondered if it was against logic or style definitions to leave out the variable n
, directly jump to the condition part and compare i to strlen(s)
Original:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main (void)
{
printf("Input\n");
string s = GetString();
for (int i = 0, n = strlen(s); i < n; ++i)
{
if (s[i] >= 'a' && s[i] <= 'z')
{
printf("%c", s[i] - ('a' - 'A'));
}
}
printf("\n");
}
My approach:
for (int i = 0 ; i < strlen(s); ++i)