Questions tagged [string]
The string tag has no usage guidance.
90
questions
0
votes
0
answers
81
views
cs50p camelcase
I am writing a for loop to iterate through a string, whenever the loop detects an uppercase character it will insert an underscore.
My question are as follows:
I am able to insert the underscore into ...
0
votes
0
answers
380
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
...
0
votes
0
answers
12
views
Value of variable getting restated just immediately before printing
I'm trying to write a simple program to convert all letters of string to lower case letters. For that I created a function called 'strlower'. Initially I tried to return an array of chars (which ...
0
votes
0
answers
30
views
I keep getting the error "more % conversions than arguments" when trying to implement a string
#include <stdio.h>
#include <cs50.h>
int main(void)
{
string name = get_string("whats your name?\n ");
printf("hello, %s ,name\n");
}
1 error generated.
make: *** [: ...
0
votes
1
answer
10
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 ...
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 ...
0
votes
1
answer
3k
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("%...
0
votes
1
answer
59
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, ...
0
votes
1
answer
234
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 ...
0
votes
2
answers
604
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 "...
0
votes
1
answer
140
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.
0
votes
1
answer
36
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
2
answers
32
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
1
answer
222
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
1
answer
28
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
1
answer
1k
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
1
answer
81
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
2
answers
306
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
1
answer
87
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
1
answer
106
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
1
answer
73
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
1
answer
51
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
1
answer
631
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
1
answer
290
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
1
answer
41
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
1
answer
308
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
1
answer
35
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
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>
#...
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(...
0
votes
1
answer
64
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
2
answers
63
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
1
answer
382
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
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 >...
0
votes
1
answer
531
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
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, ...
0
votes
1
answer
55
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
1
answer
237
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
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 ...
0
votes
1
answer
25
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
1
answer
199
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
2
answers
275
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
1
answer
505
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
2
answers
209
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
1
answer
444
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
1
answer
45
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
1
answer
175
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
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 = ...
0
votes
1
answer
151
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
2
answers
96
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
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 ...