Hot answers tagged

2 votes
Accepted

What's the C equivalent for "string input = GetString();"

If you know in advance how big of a string you are willing to accept, you can put the limit into your scanf argument itself. Try this small program: #include <stdio.h> int main(void) { char ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

Trying to Increment Characters in a String

One way would be to interpret characters 'a' to 'z' as digits in a number with base 26, start at "aaaa" (representing 0), and then adding 1 to the last string. Add or subtract 'a' for conversion ...
Blauelf's user avatar
  • 20.9k
2 votes
Accepted

C: Vigenere - incompatible pointer types passing 'char **' to parameter of type 'const char *

The error comes from here: for(int l=0; l<strlen(argv); l++) Think about it. strlen() wants a const char* or char*. You gave it argv, which is an array of the command line arguments. Because argv ...
SuperNovaCoder's user avatar
2 votes
Accepted

Pset5: strcasecmp doesn't return 0 when given the same string input

Perhaps there's a slight oversight in your code. Look at the following: lc_word[len + 1] = '\0'; Now, say that the word is "Cat". Length is 3 so len = 3. Remember that arrays start at 0,...
Cliff B's user avatar
  • 68.7k
1 vote

Error: format specifies type 'char' but the argument has type 'string'

The cs50 function get_string() takes care of writing to name. It both prints out the message "What is your name" and puts the user input into name. The scanf line is unnecessary and can be ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

String to Char in C

simple answer. You can't. That's because a string is a collection of sequential chars. Each char can be accessed as if it was in an array. For example, say you had string mystring. Then the third ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

While defining a string using char*,how does it know where to stop?

Character pointers are normally used to build literal strings, the most usual way is to make a statement of the following type: char *name = "my name is very long"; Some things you need to know ...
MARS's user avatar
  • 5,169
1 vote

pset 2 initials: trouble printing only first char and char after space

You should print uppercased name[0] if it's not a space and is either the first character or following a space. If it's the first character, there's no previous element, but conveniently, the || ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

C: Trouble with isalpha and char* - Error: expected expression

I guess you mean if (isalpha(word[i])), with word being a char[] or char*, and i being something like an int? Could you maybe clarify your question by adding the surrounding code to your question?
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

Help with converting 2 or more chars to a single string

Create an array of char, or a pointer to char with enough heap memory allocated using malloc (remember strings require a termination character '\0', so are longer than their content by one character). ...
Blauelf's user avatar
  • 20.9k
1 vote

What's the C equivalent for "string input = GetString();"

Funny thing is that I can't get much to work right in cs50.h so I've just been looking up standard c programming techniques. It's just been much easier to find working examples on the Internet using ...
George Ou's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible