Questions tagged [array]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
12 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
20 views

Readability compiling issue

Readability (Problem Set 2) #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <math.h> // Letters detects letters // Words detects ...
0
votes
0answers
44 views

Encrypt plaintext in substution.c

Here is my encryption of plaintext after validation the key. //Encrypt Code string plaintext = get_string("plaintext: "); // int array[26] = {0}; string encText = plaintext; //converts user ...
0
votes
1answer
46 views

My code for Caesar gets segmentation error when executed, but in debugger it works fine

I'm getting a segmentation error as soon as I execute this program. I've run it through the debugger and it works fine and outputs the correct ciphertext. There's gotta be something going on in the ...
0
votes
1answer
191 views

check50 claiming pairs are sorted incorrectly

On Problem Set 3, check50 has flagged my program as not having sorted the pairs correctly. However, the pairs array appears to be sorted in every case I've tried. I used insertion sort and had ...
0
votes
1answer
37 views

Why is this generating wrong output and Runtime - out of bound error?

I have a program below, which gets some random numbers from users and then multiply every second to the last digit by 2, stores it into an array and print out the value of each array index. It seems ...
0
votes
1answer
29 views

In pset2, Vigenere, I made and used an array that I would like for it to be explained

I’ve successfully solved Caesar and Vigenere pset but made and used an array that I stumbled upon through trial and error but don’t exactly know why and how it worked. I’m hoping someone could clarify ...
0
votes
1answer
26 views

PSet2 why isn't this providing output

This segment of code only prints out blank lines. Key is the correct integer, but I must be handling the array of characters incorrectly. Thoughts? int key = atoi(argv[1]); for (int i = 0, c = ...
0
votes
2answers
119 views

Pset3 Resize Array not storing data properly

I'm not sure where the issue is here, but from the looks of debug I only store anything in my horizontal array (line) once despite seeing the debugger hitting that section of code properly. I assume I ...
0
votes
1answer
54 views

Pset2 Vigenere, array with garbage

I am getting some garbage values when declaring my array. I kinda understand that when declaring without initializing it provides garbage values, but I don't understand why the array is larger than ...
0
votes
1answer
60 views

Caesar not getting output

I'm stuck troubleshooting what is wrong with my code. It prompts for plaintext correctly, but when entered returns a blank "ciphertext: ". # include <stdio.h> # include <cs50.h> # include ...
0
votes
1answer
18 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 ...
1
vote
1answer
122 views

array size in C

I have question regarding array size declaration in C. I see that if I declare an array in the main function without specifying its size like int arr[]; arr[0] = 7; arr[1]= 8; it shows an error ...
0
votes
1answer
33 views

How to get maximum element of array from index a to index b?

I keep getting the error format specifies type 'int' but the argument has type 'int ()(int , int, int)'. printf("%d", get_max); I'm new to pointers and coding C in general and still haven't ...
0
votes
1answer
22 views

Why am I able to insert an element into a hash tree via Main() but not via a function call?

I'm fairly certain this has something to do with pointers and the function using copies instead, but I'm not sure how...because I've inserted the pointer as a parameter for create(); #include <...
1
vote
1answer
115 views

Pset2: Copying string contents

I just can't seem to get this right. The example in the week 2 short Arrays is as follows: int foo[5]{1,2,3,4,5}; int bar[5] for(j=0;j<5;j++) { bar[j]=foo[j]; } This does not seem to work with ...
0
votes
1answer
167 views

CS50 PSET2 code will not compile

I would appreciate any help that could be given with my code below (+ error codes below that): My code will not compile and the primary error apparently is an "undeclared identifier" refering to ...
0
votes
1answer
120 views

Problem accessing the last element of the array

I've decided to implement the load function using trie, which I've defined as typdef struct trie { struct trie letters[27]; bool isWord; }trie; then later, when I try to ...
0
votes
1answer
33 views

Pset4 - Array declaration- Heap

In shorts of Pset4 it was mentioned, that pointers are created in heap. Does it mean, that all arrays are stored in heap?
0
votes
1answer
85 views

Pset5 Dictionary C Struct Array Call In Load Function Issue

I've defined the struct as following: // Node struct typedef struct node { // Node value char word[LENGTH + 1]; // Node Pointer to next value/node struct node* ...
0
votes
1answer
907 views

I'm getting a runtime error on an array and I'm not sure why:

The following code Compiled but gave me an error (credit.c:21:7: runtime error: index 15 out of bounds for type 'int [15]') on the last line included while running: int m; int r; int counter; int ...
1
vote
1answer
33 views

Passing SQL values into arrays

I'm designing a budgeting website for the final project. One of the features that I want to implement is to be able to track how much money you've spent for each item category. The SQL command that I'...
0
votes
1answer
56 views

pset vigenere skipped over if statement

for (int i = 0, j = strlen(s), k = 0; i < j; i++, k++) { if (isalpha(s[i])) { if (isupper(s[i])) { if (argv[1][k] ...
0
votes
3answers
200 views

pset2 vigenere shifting characters by the same

for (int i = 0, j = strlen(s), k = 0; i < j; i++, k++) { if (isalpha(s[i])) { if (isupper(s[i])) { if (argv[1][k] != '\0') { printf("%...
0
votes
1answer
25 views

pset7: why do we need [0] in from of list? (e.g. someData[0]['dic']?)

Just completed pset7, gosh it was a long one, took a month! Am curious as to why we need to have a [0] in front of the list to get the "pure" data? For instance, when we get back a list while ...
0
votes
2answers
2k views

pset2 caesar converting from ascii to alphabetical

#include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, string argv[]) { if (argc == 2) { int ...
0
votes
1answer
52 views

Declaring an array of structure pointers

How to declare an array of structure pointers? I need to create a collection of linked list. Is it same as declaring ordinary arrays? If
0
votes
1answer
109 views

Array declaration need explicit size?

Can I create an array with no specific size or intializer? I'm trying to make an array of 26 english character but I don't want to just declare 26 slots right from the beginning int main(void) { ...
1
vote
1answer
424 views

Pset4 Resize.c Array Overstepping

I have been stuck on resize for a while. I am currently struggling on the vertical portion of resize. I am using the "rewrite" method as explained in the problem spec. My program does resize an image ...
0
votes
1answer
966 views

Pset4 - Recover (usage of sprintf)

When I am working on Pset4 - Recover, I realize I do not understand the concept of array and pointer. Although I finally worked it out, I would be very grateful if you guys can explain the following: ...
0
votes
1answer
50 views

Game of Fifteen - Move Function - getting wrong coordinates?

I have been working on the game of fifteen problem and seem to be having an issue. I keep getting an "Illegal Move" when it is a legal move. I think I have found part of the issue and I would just ...
0
votes
1answer
853 views

Why this code leads to segmentation fault?

1) In CS50 ide, it does not even compile giving error: format specifies type 'int *' but the argument has type 'int' [-Werror,-Wformat] scanf (" %d", array[n]); 2) In codeblocks, it runs ...
0
votes
1answer
58 views

handlign multidimesional arrays as function arguments and return values

So I stuck at the pset3, at the place where you need to implement game of fifteen. How can I pass multidimensional array as an function argument? And how can I return multdimesional array as a ...
0
votes
1answer
158 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
607 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
178 views

How to use fseek along side arrays? Pset4 recover

I'm re-wrote this code and did not get any output or error. Tried valgrind and nothing was leaked. I suspect it's either: 1) my fseek is not moving my cursor in inpt 'card.raw' 2) and/or.. because ...
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
42 views

pset3 move: won't move tiles in the same row

So I have reviewed similar questions on here but can't quit fix my move code. It will correctly move tiles from within one column to row below (say 3 in the initial position for a 3x3 board). But it ...
0
votes
2answers
5k views

Subscripted value is not an array

I am using exactly the same code as at HowStuffWorks to create a bubbling sorting. But I cannot compile code as I get the following error message: sorting.c:29:22: error: subscripted value is not an ...
2
votes
2answers
119 views

how effective would it have been to use an array for the dictionary?

I just completed pset5 using a trie, but I'm curious about other methods. How effective would it have been to load the dictionary into an array and then use a binary search function to locate words ...
0
votes
1answer
34 views

Taking an array as input from User and Displaying the same back

I'm trying to take a list of numbers from user as input and store it in an array. Later I'll be displaying this array using a printf function. I'm trying to take this input in 2 ways: as user prompt ...
0
votes
1answer
42 views

2D array of given size

I want to create a 2D array of ints, where the array's dimension is given at run time (not compile time). So far, I have been using: int **ptr = malloc(m * sizeof(int*)); for (size_t i = 0; i < m;...
0
votes
1answer
402 views

Difference between Pass by Value and Pass by Reference (a practical example)

at the end of Doug's video on arrays he explains how variables get passed in function calls in comparison to how arrays work. void set_array(int array[4]); void set_int(int x); int main (void) { ...
1
vote
2answers
549 views

declaring char array vs malloc

I was watching the week 5 lecture and David said that a chunk of memory can be allocated two ways: using malloc(); declaring an array of a certain size (char buffer[10]). Is there really any ...
0
votes
1answer
85 views

How do you specify a section/segment of an array?

I am working on the binary search project in pset 3. I want to specify that if the sought value is greater than the middle value of the sorted array, that the function should then only look in the ...
0
votes
1answer
57 views

difference between string, pointer, array and int

while it hasn't been something which really stopped me from learning, there is something which has been keeping me awake for the last few days... What is the difference between: #define x 5 int i; ...
0
votes
2answers
2k views

Excess elements in scalar initilizer?

#include <cs50.h> #include <stdio.h> int example[]; int main(void) { int example = {1,2,3}; for (int i = 0; i < 3; i++) { printf("%i \n", example[i]); } } Why ...
0
votes
1answer
239 views

I've use array pointer method in pset2 (initials.c) but it return "Segmentation Fault (Core Dump) Why?

I'm working on pset2 using array pointer method, but unfortunately, the program return "Segmentation Fault (Core Dump)" I've post a picture of my code below.Can I use this method? or I have to use if ...
0
votes
1answer
327 views

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

I'm trying to generate two independent characters arrays. The first one must contain the alphabet in lowercase and the second one, in uppercase. My code works but in the second case, the output ...