Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
21
votes
2answers
58k views

Difference between char and char* in c

suppose we declare two variable char s[]= "hello" char* p = "hello". what is the difference between these two?
3
votes
2answers
11k 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 ...
2
votes
3answers
4k views

regarding using lib string.h for lowercase

My code #include <stdio.h> #include <string.h> #include <cs50.h> int main(int argc, string argv[]) { string word = "HiMyNaMeIsJames"; strlwr(word); printf("%s", word); }...
2
votes
3answers
845 views

What stuff that's inside array[-1] or array[n + 1]?

Here a portion of the loop I used to implement insertion sort algorithm: while (j > 0 && values[j - 1] > actualElement) { // place the unsorted element inside the correct position ...
1
vote
1answer
318 views

about strings and arrays

while declaring arrays we have to mention size of arrays as arrays cannot be dynamic similarly string is array of chars how can we not mention size of array we simply use Getstring() or scanf
1
vote
2answers
2k views

GetString() giving me a segfault in C

I am running a program in C using a GetString function (not from the CS50 library). When I run the program I get a segmentation fault error. In GDB, when I backtrace it tells me: Program received ...
1
vote
2answers
880 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> #...
1
vote
1answer
66 views

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

Here says: Why did we allocate an array of size 12 for our representation of that int as a string? No worries if the reason’s non-obvious, but give some though as to how wide the most positive (or ...
1
vote
1answer
203 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 ...
1
vote
2answers
238 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...)
1
vote
2answers
206 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 ...
1
vote
1answer
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) { ...
1
vote
2answers
2k views

Checking the base address of pointer string

#include <stdio.h> #include <string.h> int main(void) { char *a="World"; char *b; printf("a=%p\n",&a); // Base address of a b=a; // Base address of a ...
1
vote
2answers
102 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
2answers
24 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
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
449 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
428 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) ...
0
votes
1answer
927 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
70 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
39 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
1k 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 ...
0
votes
3answers
599 views

Assing argv[1] to a string variable (vigenere)

I'm stuck. There's a way to assign argv[1] to a string variable?, like: string keyword = argv[1];
0
votes
2answers
404 views

How to check string argv[] for errors?

hope I can get some help here. I'm only at week 3 in CS50 and wanted to play around with command-line arguments a bit before moving on. I got this working (diagonalizing input), but couldn't figure ...
0
votes
1answer
2k views

printf is changing string contents

I finished PSet2 with all the correct results, but I'm trying to figure out why I had to change some of my code in initials.c to make it work properly. The original code is as follows: #include <...
0
votes
3answers
2k views

string variable is not working

I am trying to use a string variable after having included the header file stdio.h but for some reason it is not working. The color of the word "string" does not change as opposed to int, float, ...
0
votes
1answer
242 views

strcat segmentation fault

To solve caesar's cipher, I'm trying to concatenate each character onto the end of the cipher string (as c[i] = "blah" didn't work). strcat isn't working for me, though. First of all, this thing ...
0
votes
3answers
9k views

How to Check Whether a String Contains Non-Alphabetical Characters?

I'm stuck when I'm trying to identify whether the command-line argument input contains only alphabetical chars. Here's my code: When I tried to run the program, it showed an error message. I don't ...
0
votes
1answer
121 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
1answer
12 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
1answer
110 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
2answers
125 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
1answer
37 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
1answer
35 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
1answer
79 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
47 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
544 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
238 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
39 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?
0
votes
1answer
33 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
198 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
191 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
163 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
124 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
5k 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
146 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
1k 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 ...