Hot answers tagged

4 votes

Main difference between char & string, can they be used randomly

string is a variable type defined by the CS50 library - it does not normally exist in C. Looking at the code for CS50.h will show this: /* * Our own data type for string variables. */ typedef char ...
user avatar
  • 2,625
3 votes
Accepted

fgetc with sleep unexpected result

The function printf writes to the standard output stream (aka stdout). The stdout usually buffers the data and then flushes it at some point (usually when a newline character is written or when it's ...
user avatar
  • 17.4k
3 votes
Accepted

In breakout, why use 12 char to store an int?

The question is hinting at you to think about why the array is initialized with a size of 12.
user avatar
2 votes
Accepted

Question of inputing an array of char

First in the struct definition, you are the declaring a pointer to a char (char*), so if you don't want to use GetString(), when you try to store something that is not a pointer on any of this ...
user avatar
  • 1,369
2 votes
Accepted

c prog - Generate ''ALPHABET'' and ''alphabet'' in arrays, wrong output

The problem is simple. You have created two string arrays. Each holds the 26 letter alphabet, one lower case, the other upper case. They are created in sequential memory. In this case, the UC array ...
user avatar
  • 63.5k
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 ...
user avatar
  • 18.4k
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 ...
user avatar
  • 20.7k
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 ...
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,...
user avatar
  • 63.5k
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 ...
user avatar
  • 63.5k
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 ...
user avatar
  • 63.5k
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 ...
user avatar
  • 5,172
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 || ...
user avatar
  • 20.7k
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?
user avatar
  • 20.7k
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). ...
user avatar
  • 20.7k
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 ...
user avatar
1 vote

weird symbols in caesar

The formula, as it is in the specs, and as you're using it, only works if the alphabetic chars are in a range 0 - 25. That is, 'a' == 0, 'b' == 1, etc. That's not the case because that's not the ...
user avatar
  • 1,677
1 vote
Accepted

what is the funny symbol printed when char[] uninitialized

That's a non-alpha ASCII value that is attempting to be printed. If you really want to know what it is, try printing it as an integer. Something along the lines of printf("the char ascii value is %i\...
user avatar
  • 63.5k
1 vote
Accepted

Check function error integer to pointer conversion

You have just placed the parenthesis in the wrong place. It shouldn't be if(strcmp(temp, thisNode->word == 0)) But if(strcmp(temp, thisNode->word) == 0) The condition thisNode->word ==...
user avatar
  • 7,326
1 vote

Comparing chars

Your problem is much more basic and simple. Look at these lines: char x; // a char variable char *y; // a pointer to a string y = "a"; // loads a string into memory at y if ...
user avatar
  • 63.5k

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