Questions tagged [array]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
15 views

How to find if element is not in an array

Does anyone know of an easy way in C to check if a an element is NOT in a given array? I think it would be fairly easy to determine if an element IS in an array by looping through it and seeing if an ...
0 votes
0 answers
86 views

pset2 - Bulbs - reversing array turns out wrong

I managed to make the right sequence of binary code (in reverse). Next, I do a for loop for reversing it, but it prints out wrong. I have no idea what happens, as the original array is correct, ...
  • 1
0 votes
2 answers
106 views

pset2 bulbs - getting array out of while loop

I'm working on the pset2 Bulbs problem and I've come to a place where I don't know what to do next. This code takes user text input and converts it to ascii; I can see that the array is being filled ...
  • 1
0 votes
0 answers
66 views

"Format specifies type 'int' but the argument has type 'int * "-- at C

I have a problem with the main program , the main get an array - dynamic and didn't print the actual result I need. int main() { int arr[] = {1,2,2,4,1}; int n = 5; int* ptr = NULL; int iseven = 1; ...
0 votes
1 answer
30 views

Converting an array to lowercase

I am trying to convert an array to lowercase, and store the values as a new array. #include <cs50.h> #include <stdio.h> #include <ctype.h> int main(int argc, string argv[]) { ...
0 votes
1 answer
35 views

comparison between pointer and integer ('const char' and 'char')

I'm not familiar with C, not sure what this error means.. could anyone help? #include <ctype.h> #include <cs50.h> #include <stdio.h> #include <string.h> // Points assigned to ...
  • 101
0 votes
1 answer
47 views

Undeclared Identifier error in array

In the code below (photo), I am trying to index into the two different arrays, one with capital letters and one with lowercase letters. When I make this program, I keep getting the following error ...
0 votes
1 answer
15 views

How to get accurate float average of numbers

I'm in Lecture 2 on Arrays, and I am playing with the example Professor Malan gave about taking a user's input for the number of test scores, as well as for the scores themselves, and outputting the ...
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
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
1 answer
24 views

substitution question segmentation fault issue

I am doing the substitution question and I keep running into this segmentation fault issue but i do not understand what exactly is causing the memory access issue. once j=4, the memory fails to be ...
0 votes
1 answer
255 views

Use of undeclared identifier 'num'

I dont really know where im wrong. it gives me "use of undeclared identifier 'num'" i allready tried to solve it but i have no clue of what is going on #include <stdio.h> int maxc = 0,...
0 votes
1 answer
24 views

Why is an Array longer then the input?

why we can access more information than the lenght of the array? I thought that after the Null (0) the array ends. Why we can access position 40?
  • 3
0 votes
3 answers
26 views

Error retrieving return values ​from a function

I am currently studying coding in C language and I have doubts about the return of functions, what I am trying to do is the following: Call the number () function and pass 3 values ​​of the integer ...
0 votes
1 answer
56 views

Help with Either Command Line Argument or Arrays for Problem set 2 Caesar

I am on Problem Set 2: Caesar. Right now I'm trying to write code that first checks if the second command line argument is a int and if it does prints the integer. I got my program to compile after ...
0 votes
1 answer
30 views

When I'm creating array

This has me confused. In the following code, I create an array of characters initialized at size 7. The array needs to store at least 6 characters, so I've made it large enough to do that (I think?). ...
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
58 views

Having Trouble using StrCpy with Command Line argument for Problem Set 2 Caesar. Trouble with Array

Hello I'm still fairly raw at this coding thing so i'm sure im making rookie mistakes. I'm doing Problem Set 2 caesar and I've hit a wall and haven't been able to move forward. What I have been trying ...
0 votes
1 answer
15 views

How can i arrange the output in decending order In this program? [closed]

#include <stdio.h> int main() { int n,i; printf("Enter a number: "); scanf("%d",&n); for (i=0; i<=n; ++i) { if (i%(7*13*19)==0) { ...
  • 3
0 votes
1 answer
20 views

PSet 5 Speller - Expected Identifier

Been stuck on Speller for 2 days and could really please use some help. My initial idea is just to create an array of linked lists with 26 buckets (N = 26) and very simply hash the words by only the ...
  • 3
0 votes
1 answer
68 views

Getting different outputs when I use debug50 and when I run the program

When I use debug50 on this program I get 26 as the value of 'a' but when I run it I get random large values of 'a'. #include <cs50.h> #include <stdio.h> #include <string.h> #include &...
0 votes
1 answer
874 views

cs50 array initializer must be an initializer list

i have started coding in c but i keep getting errors i don,t know how to solve maybe it is because i am used to coding in php language but i hope anybody can help me #include <stdio.h> #include &...
  • 1
0 votes
1 answer
39 views

Having trouble identifying non-decimal digit in Caesar PSET 2

I'm working on Caesar from Problem Set 2. I have done the first step to check for a single command line argument, but I'm stuck on how to check the argument to see if any characters are non - decimal ...
1 vote
1 answer
155 views

Week 2 passing array example problem?

Hi, I have problem understanding the concept of 'passing an array by reference instead of value' and I cant understand this example. Can anyone explain to me why does it take 10, 22 as final answer?
  • 13
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
90 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
1 answer
58 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
1 answer
287 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
1 answer
51 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
1 answer
41 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
1 answer
27 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 = ...
  • 33
0 votes
2 answers
140 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
1 answer
57 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 ...
  • 13
0 votes
1 answer
78 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 ...
  • 21
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 ...
1 vote
1 answer
397 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 ...
  • 312
0 votes
1 answer
124 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 ...
  • 1
0 votes
1 answer
24 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
1 answer
131 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
1 answer
408 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
1 answer
675 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
1 answer
34 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?
  • 5
0 votes
1 answer
89 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
1 answer
3k 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
1 answer
37 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
1 answer
58 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
3 answers
203 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
1 answer
28 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 ...
  • 179
0 votes
2 answers
3k 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
1 answer
66 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