C For loop skips first iteration and bogus number from loop scanf

Let’s take a look at the problem one by one: newline Remains in stdin after No. or Persons Read printf(“\n\nEnter name: “); safer_gets(person[i].full_name, 35); /* This is the step being skipped */ It is skipped because your safer_gets() reads only to the first ‘\n’ (newline character — not a carriage-return, that is ‘\r’). However, the … Read more

Why can’t “transform(s.begin(),s.end(),s.begin(),tolower)” be complied successfully?

Let’s look at a list of options starting with the worst and moving to the best. We’ll list them here and discuss them below: transform(cbegin(s), cend(s), begin(s), ::tolower) transform(cbegin(s), cend(s), begin(s), static_cast<int(*)(int)>(tolower)) transform(cbegin(s), cend(s), begin(s), [](const unsigned char i){ return tolower(i); }) The code in your question, transform(s.begin(), s.end(), s.begin(), tolower) will produce an error … Read more

Do I need to cast to unsigned char before calling toupper(), tolower(), et al.?

Yes, the argument to toupper needs to be converted to unsigned char to avoid the risk of undefined behavior. The types char, signed char, and unsigned char are three distinct types. char has the same range and representation as either signed char or unsigned char. (Plain char is very commonly signed and able to represent … Read more