Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
33 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 ...
0
votes
2answers
22 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 ...
0
votes
1answer
11 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 = &...
0
votes
1answer
15 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 &...
0
votes
1answer
47 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 ...
0
votes
1answer
45 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]= ...
1
vote
1answer
20 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 = ...
0
votes
0answers
25 views

Readability(checking punctuation to determine number of sentences)

here is my code; trying to detect punctuation (!, ., ?) to determine the amount of sentences, however keep getting error messages. would appreciate any help. my code and error messages are below; #...
0
votes
1answer
36 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 ...
0
votes
1answer
36 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) { ...
0
votes
1answer
13 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 ...
0
votes
1answer
17 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 ...
0
votes
1answer
429 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 ...
0
votes
1answer
186 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 ...
0
votes
1answer
34 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?
1
vote
1answer
103 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 ...
0
votes
1answer
18 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 ...
1
vote
2answers
540 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> #...
0
votes
1answer
24 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(...
0
votes
1answer
19 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 ...
0
votes
2answers
59 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 ...
0
votes
1answer
256 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 ...
0
votes
1answer
434 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 >...
0
votes
1answer
275 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); }...
0
votes
2answers
195 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, ...
0
votes
1answer
39 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 ...
0
votes
1answer
156 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);
0
votes
1answer
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 ...
0
votes
1answer
21 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 ...
0
votes
1answer
104 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?
1
vote
2answers
195 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...)
0
votes
1answer
484 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 (...
1
vote
2answers
196 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 ...
0
votes
1answer
415 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) ...
1
vote
1answer
44 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) { ...
0
votes
1answer
160 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 ...
0
votes
1answer
683 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 = ...
0
votes
1answer
103 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 ...
0
votes
2answers
93 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 ...
0
votes
2answers
3k 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 ...
0
votes
1answer
125 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 ...
0
votes
1answer
35 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 ‘...
3
votes
2answers
8k views

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

I am trying to become less dependent on the cs50.h library. I have tried different combinations to replace this line string input = GetString(); but I can't get anything working. Compiler keeps ...
0
votes
3answers
307 views

Sentinel value in arrays

Why don't we use the backslash zero in integer arrays to save memory or prevent overflow like character arrays or strings?
0
votes
1answer
69 views

Why doesn't this code work?

#include <stdio.h> #include <string.h> #include <cs50.h> int main () { string s = GetString(); int n=strlen (s); string c [n]; for (int i=0; i< n; i++) { ...
0
votes
1answer
995 views

What happens when you assign a character string to a char* instead of writing element by element?

I have a question about strings that hopefully someone can help with. I realise that doing something like: char* word = malloc(4); word = "THE"; is not really correct (as word is really a pointer to ...
0
votes
1answer
55 views

This is my code for vigenere pset2 and it is giving 4 errors please help.Errors are as follows

incompatible integer to pointer conversion assigning to 'string' (aka 'char *') from 'int' [-Werror,-Wint-conversion] key[j]=(argv[1][j])-65;//converting uppercase key to index 0 ...
0
votes
1answer
38 views

I have written this code for vigenere and it is giving 02 errors

Here is my code it is giving two error described below. on line 34 key[j]=tolower (argv[j])-97; I can't understand what's the error. on line 50 and 55 same problem printf("%c",((p[k]-65)+(key[c%klen])...
0
votes
1answer
39 views

How can i get int value of ith charactor in the string

i want to get the integer value of ith character in the string, this is my program please tell me mistakes. #include <stdio.h> #include <cs50.h> #include <string.h> int main (void) ...
0
votes
1answer
750 views

char* and read-only memory

Take a function that creates a char* and does something with it. void print_hello_twice() { char* hello = "hello"; printf(hello); printf(hello); } This is a silly pointles example, but I ...