I am trying to find the lenght of a string using size_t in my program, then using that integer to determine how many times my program loops to perform a letter shuffle (+6 to a letter so a = g when saved).
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stddef.h>
int main(void)
{
FILE *file;
int i, fnlen, lnlen;
char firstname[15], lastname[15], *ptr;
fflush(stdin);
printf("Please enter the first name of the player:");
if(fgets(firstname, sizeof(firstname), stdin) != NULL)
{
size_t fnlen = strlen(firstname);
}
printf("Please enter the last name of the player:");
if(fgets(lastname, sizeof(lastname), stdin) != NULL)
{
size_t lnlen = strlen(lastname);
}
for(i = 0; i < lnlen; i++)
{
lastname[i] = (char)((lastname[i] - 'a' + 4) % 26 + 'a');
}
for(i = 0; i < fnlen; i++)
{
firstname[i] = (char)((firstname[i] - 'a' + 4) % 26 + 'a');
}
file = fopen("text.txt", "wt");
if(!file)
{
printf("File is not able to open.");
exit(1);
}
fprintf(file, "Firstname is : %s\n""Lastname is: %s\n", firstname, lastname)
When I open the file its saved to, the first name is shuffled properly, but has 8 characters when i typed 5, and the lastname is correctly saved, but the letters are no shuffled, they have just output what I input in the fgets