Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

cs50 string not registering

stack.imgur.com/OShHG.png I'm following along with the cs50 course why is my string not registering and changing color like the example code?
CONEDIGGITY's user avatar
0 votes
0 answers
547 views

Invalid operands to binary expression ('std::string' (aka 'basic_string<char>') and 'char')

int main(){ int t; cin>>t; while(t--){ int n,sum=0; cin>>n; string s[n]; for(int i=0;i<n;i++) cin>>s[i]; int dec_value = 0; // Initializing base value to 1, i.e 2^0 ...
Abhishek kumar Singh's user avatar
0 votes
1 answer
11 views

Idk why this error is coming can anyone help

Link to problem: https://leetcode.com/problems/shifting-letters/#:~:text=Shifting%20Letters%20%2D%20LeetCode&text=You%20are%20given%20a%20string,z')%20%3D%20'a'%20. string shiftingLetters(string ...
Samartha Khare's user avatar
1 vote
2 answers
62 views

Week 4 lecture: can't reproduce string != string

In the lecture of week 4 in CS50x, David illustrates how two strings can't be compared with two equal signs (==), and instead, strcmp() has to be used. I can't reproduce this locally or on CS50's IDE ...
therubberduck's user avatar
0 votes
1 answer
4k views

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

This is the code written: #include <stdio.h> #include <cs50.h> int main(void) { string name = get_string ("what is your name\n"); scanf("%s", &name); printf("%...
Splendid Digital Solutions's user avatar
0 votes
1 answer
86 views

Isalpha not working for all char of my string

I'm trying to use the isalpha() function to check whether all characters of a string are letters or not. However, when I use the debug50 module, it looks like after the first character of the string, ...
jamba's user avatar
  • 3
0 votes
1 answer
286 views

Speller not working! What's going on?

My function returns this: WORDS MISSPELLED: 375902 WORDS IN DICTIONARY: 143091 WORDS IN TEXT: 376904 TIME IN load: 0.02 TIME IN check: 1.20 TIME IN size: 0.00 TIME ...
bobthebuilder's user avatar
0 votes
2 answers
885 views

Caesar : Extra random characters at the end of a char ciphertext array

I'm having a problem with an output. Sometimes output adds an extra characters, different each time the code runs. For example, when I use key "1" and write "a", it displays "...
D3sl0nG3r's user avatar
0 votes
1 answer
196 views

String to Char in C

How can I convert a String to a Char in C? Please help. I am unable to do that and I need it urgently. I need it for readability.
Saara Luthra's user avatar
0 votes
1 answer
37 views

Pset5 Speller. Treating the letter 's' as a valid word when using large dictionary?

I'm very puzzled my program seems to work correctly apart from one thing, when I run speller with large dictionary, the letter "s" is treated as a correctly-spelled word. I ran a test using ...
t-monny's user avatar
0 votes
2 answers
35 views

Problem in C programming about condition

Well, I am learning C programming.Today I faced a problem while coding. I have made a string variable named,"answer". But when I wrote a condition, I found an error message but I don't know ...
Artinxt's user avatar
0 votes
1 answer
342 views

Find hex values inside a string in C?

I have a long string "given_string", and I'm trying to find hex values within that string. Here's a simplified example: /* Find a sub-string in a given string: */ char * given_string = &...
echorashmi's user avatar
0 votes
1 answer
29 views

When I multiply my array by 2 it doesn't give expected value

Also, please when I try to add "firstnumsum", it doesn't give expected value and I don't know what to do. #include <cs50.h> #include <stdio.h> #include <string.h> #include &...
Gloria Isedu's user avatar
0 votes
1 answer
2k views

incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **')

Im writing a funtion that takes string as a argument and gives back a integer. This function counts lenght of a string entered at the command line argument. I get an error :" incompatible pointer ...
RafalH123's user avatar
0 votes
1 answer
92 views

i don't know what's wrong with my code. Trying to convert from string to long

INPUT int main(void) { long long cardnumber, calc; string credit[0]; string nonnumeric; //long long calc = card number; int countcardcharacters = 0; long long c; //user input do { credit[0]= ...
Gloria Isedu's user avatar
1 vote
1 answer
463 views

Segmentation fault with overwriting chars

I tried overwriting cipupperalphabet[j] from a A to a B, but it has caused a segmentation fault. string upperalphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string cipupperalphabet = upperalphabet; int j = ...
xander's user avatar
  • 11
0 votes
1 answer
89 views

datatype string is malfunctioning in pset2 2020

I am currently working on pset2 cs50 2020. The Ceasar's cipher problem. I have managed the code for the first few steps and I think I know how to do the rest however I'm having an issue declaring ...
Renée's user avatar
  • 19
0 votes
1 answer
166 views

Replacement of string with char* in any general case

Take a simple program where i want to count the number of vowels in a string, this i've easily implemented using string.h. But when i try that with char*: #include <stdio.h> int main(void) { ...
Musical_Ant's user avatar
0 votes
1 answer
84 views

Try to use += on string to stack char(s) in C

I know it sounds real stupid, but It is cuz I just lightly learned Java and Python last year... now I am try to do C properly with CS50. on week 2, there is Caesar encipher text program task. I ...
Minsu's user avatar
  • 5
0 votes
1 answer
68 views

How to swap strings?

The main problem comes when we swap strings of unknown lengths. Lets say we have two strings assigned to two variables say a, b. Now if I use a temporary string say c, and use strcpy(c,a), then use ...
Sandesh Goli's user avatar
0 votes
1 answer
644 views

Plurality fails to compiles

I always work on Psets on my local machine and replace string with char * so I don't have to use the CS50 library in my header files. This is the only explanation I have for why my code doesn't ...
Florestan Korp's user avatar
0 votes
1 answer
314 views

check function in speller pset5, not quite understanding the apostrophe

I am working on the check() function of dictionary.c. I am using it to test cat.txt: A cat is not a caterpillar. It says everything is correctly spelled except "not" When I check the hashtable ...
Katie Melosto's user avatar
0 votes
1 answer
45 views

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

when we define a string like char *name = some_name; and then print it printf("your name is %s",name); how does know where to stop while printing as we didn't include a '/0' at the end?
Rohit Jain's user avatar
1 vote
1 answer
309 views

vigenere output "incompatible pointer types"

I'm trying to solve pset2 vigenere, but I'm having some troubles. I'm using two functions to adapt the key to the text and then to apply the cipher. When I run the last function, I can't get any ...
faedx's user avatar
  • 25
0 votes
1 answer
42 views

sans trailing line ending?

I can't seem to find an explanation for the phrase "sans trailing line ending"? From what I can gather, line ending refers to CR (carriage return) and NL (newline) but I still can't grasp the meaning ...
MDT's user avatar
  • 1
1 vote
2 answers
1k views

Printf doesn't print whole string "11111"

String a, that is a pointer, contains 5 1's, but printf outputs only one 1. #define _XOPEN_SOURCE #include <unistd.h> #include <stdio.h> #include <stdlib.h> #...
Nikita Kokorin's user avatar
0 votes
1 answer
25 views

i want the number of line in which the function is locate , like the function "func2" is in second line so the output shoud be 2 [closed]

#include<stdio.h> #include<string.h> unsigned int FindFunctionDefn( char strFunctionName[], char strSourceCode[] ){ int n = strlen(strSourceCode); int m = strlen(...
manish_rocks's user avatar
0 votes
1 answer
96 views

Why string variable has no square bracket?

Though it's said that string is an array of characters why string variable does not have square brackets on the immediate right? In CS50 we call string as string s why not as string[]? then how can ...
Indhlal Amrith's user avatar
0 votes
2 answers
64 views

two strings (appear equivalent) return different hash

I have left some debug statements in my code so it should be easy to understand my problem. (these statements have comment DEBUG) I have manually ran crypt with salt 50 and password A. I have ...
Iain MacCormick's user avatar
0 votes
1 answer
418 views

Length of a string

How would I make it so that a string only accepts a statement that is between a certain amount of characters? An example would be a sentence between 4 and 8 characters long. Would it be strlen, and if ...
Kyle Culbreth's user avatar
0 votes
1 answer
453 views

Week 6: DNA sequence aligning example: Are running times iterative approach and reqursive same?

once again I'm asking help ( not to provide me with code example or pseudo code ), but for clarification on the problem. It seems that this double loop ( iterative approach ) for (int y2 = y; y2 >...
Gintas's user avatar
  • 107
0 votes
1 answer
648 views

String being replaced by garbage before being printed

I have this code: #include <cs50.h> #include <stdio.h> #include <string.h> string increment_str(); int main() { string s = increment_str("xyz"); printf("String: %s\n", s); }...
C1N14's user avatar
  • 1
0 votes
2 answers
201 views

Similarities (More) sometimes fails but works in most cases

For some reason, for some combinations of strings, I receive an IndexError on the compilation of Operations in application.py. However, for most cases, the table renders properly, and in every case, ...
wlh's user avatar
  • 132
0 votes
1 answer
60 views

When do I nul terminate strings?

I'm on week 4 and looking over other people's codes and I've noticed that up to this point, I've never really nul-terminated strings with '\0'. From what I understand, there are some functions where ...
doctopus's user avatar
  • 119
0 votes
1 answer
272 views

difference between int* and char*?

Why this code not is not compiling int *pkk = 5646; printf("%d\n", *pkk); printf("%d\n", pkk); but this works perfectly char *sp = "Hello"; printf("%s\n",sp); printf("%c", *sp);
d0020002's user avatar
0 votes
1 answer
41 views

string A is assigned to B. why does A change now, when B is changed?

I've finished the pset2 Vigenère problem, but encountered unwanted behaviour. So, I got the plaintext from user input and wanted to copy the value to another variable, which is to be changed further ...
Julian's user avatar
  • 15
0 votes
1 answer
26 views

Editing two similar strings

It appears that if you define one string and store the value of the string in another string and you try to change one of the strings, you'll end up changing both of them(as in the image). My question ...
Muhammad Faizan Badar's user avatar
0 votes
1 answer
223 views

String validity check when string is command line argument?

We check the string validity when we use the get_string() function. Example: if (p != NULL) Are we also supposed to check string validity when the string is entered as a command line argument?
Satanic Saint's user avatar
1 vote
2 answers
281 views

Help with converting 2 or more chars to a single string

I am trying to convert two or more chars into a single string. Is this possible, and if so, how might I go about this? (BTW I am new to programming...)
Jason_V's user avatar
  • 182
0 votes
1 answer
511 views

Convert String to an Int in Python CAESAR.PY

Please I need help. I dont know how to convert a String in an Int to complete the ASCII Formula in Python. (a = string[i] - 65) HERE IS A FRAGMENT OF MY CODE: for i in range(len(string)): if (...
user avatar
1 vote
2 answers
210 views

Trying to Increment Characters in a String

I am trying to increments the chars in my string (ie string x = (aaaa) all the way through (zzzz)). Is there a specific way I can use a loop to do this? I'm sorry if my question is newbie, I'm new to ...
Jason_V's user avatar
  • 182
0 votes
1 answer
446 views

Crypt() includes and compiling

I am currently working on pset2 crack, and I have a question regarding the use of crypt(). This is the synopsis I have got from man: SYNOPSIS #define _XOPEN_SOURCE /* See feature_test_macros(7) ...
Steve Bunting's user avatar
1 vote
1 answer
46 views

Arranging Strings using pointers

#include <stdio.h> #include <string.h> #include <cs50.h> #include <string.h> void swaps(char*s,char*t) { char*a = t; strcpy(t,s); strcpy(s,a); } int main(void) { ...
qwerty's user avatar
  • 64
0 votes
1 answer
189 views

How could you create a dynamic array of strings in C?[Beginner]

How do you create a dynamic array of strings? Like if I had this code printf("What are the names of your pets?"); what piece of code would I write to get multiple string answers from the user? (I'm ...
Matthew Ryan Hutter's user avatar
0 votes
1 answer
1k views

trail of strange characters after printing character array

I wrote my vigenere cipher program and everything works fine, but when I run check50 I get the following error:(p is the plaintext string) char c[strlen(p)]; for(int i = 0, j = 0, l = strlen(p), n = ...
Nima_R's user avatar
  • 3
0 votes
1 answer
155 views

C random string generator help? cs50

I am trying to implement a function to generate a random string consisting of only a-z characters both upper and lower case.. What is wrong with the code I wrote and how can I fix it? I am constantly ...
Ethan's user avatar
  • 1
0 votes
2 answers
97 views

Pset 2 - Vigenere Checking Command Line Input

I am working on the Vigenere portion of the pset and appear to have it totally working, yet when I ran the checker I realized that I had not created a test for non-alphabet characters in the command ...
mlh's user avatar
  • 3
0 votes
2 answers
7k views

Split a sentence ito an array of words without using strtok

I need to split a sentence contained in a char pointer into an array of words. I've tried several methods (as I cannot use strtok. The following method I used extracts the different words, but it ...
excel's user avatar
  • 29
0 votes
1 answer
169 views

strcpy doesnt work

I am trying to use strcpy to copy file names onto a path. Here is what I noticed. strcpy(a,c); strcpy(b,c); a is not the same as b or c. c's pointer seems to have advanced somehow. b and c are now ...
William Cullian's user avatar
1 vote
2 answers
55 views

warning: deprecated conversion from string constant to ‘string {aka char*}’ [-Wwrite-strings]

I'm a complete beginner who just commenced on the CS50 course through EDX. While tryin out the walkthrough lessons in the CS50 IDE (clou9), I'm getting the following warning "TEST.C: In function ‘...
Muhammed Razeem's user avatar