Questions tagged [arrays]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
3answers
36 views

I'm getting an for error expected expression. What exactly I'm I doing wrong?

I mainly want my else statement to work, but it's not working. int main(int argc, string argv[]) { if (argc != 2) { printf("Usage: ./caesar key\n"); } else if (argc == 2) { for (int i = ...
0
votes
1answer
40 views

Runoff pset 3, arrrays and indexing

I don't understand what's going on with the solutions to the voter preference and tabulate functions. I had set up a similar function to the answer with the exception that I had [voter][i] = rank; ...
0
votes
1answer
13 views

Array initialilizer must be an intitializer list or string literal

Given this text: include include int main (void) { string text = get_string("Text: "); char num[] = text; } When this is run, it gives the error as stated in the heading of this question ...
0
votes
1answer
9 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
44 views

Question for Array in C (with function e.g. set_array)

While I was doing cs50 week2. I found something hard to understand. #include<stdio.h> void set_array(int array[4]); void set_int(int x); int main(void) { int a = 10; int b[4] = {0, 1,...
0
votes
1answer
61 views

Trouble modifying elements of an array of candidates in Plurality

I'm working on Plurality of pset3. I've run into an issue modifying the vote count of each candidate. I've isolated the problem in the full program below. It appears that candidate zero = candidates[...
0
votes
1answer
17 views

Arrays and their sizes in C

I am having problems related to arrays and their sizes in C. There's something I am doing wrong, but I don't know what exactly. Here is a sample of the code: #include <stdio.h> #include <...
0
votes
1answer
21 views

[pset2][Vinegere] Code not enciphering text after certain letters, please help!

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

Pset1: Error when trying to assign single digits of int variable to array using for loop

I'm currently working on Credit. I'm trying to find the first two digits of the card number using a for loop. I've created an array named firstdigits with two elements. Then I've created a for loop to ...
0
votes
1answer
18 views

Selection Sort: Holes in Logic

#include <cs50.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { string s = get_string("Enter a number: "); string answer ...
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 ...
1
vote
1answer
238 views

Arrays of Pointers - implicit double dereferencing

Good day people! The context is resize program in problem set 4, however, the question is general. Following is how the main function begins for the relevant program: int main(int argc, char *argv[])...
0
votes
1answer
124 views

Error handling while running credit.c for pset1

I have broken the credit problem into 2 parts Checking whether the sum after the Luhn’s algorithm has a zero at the end or not If the inout integer is valid then go ahead and find the card type using ...
0
votes
1answer
59 views

PSET4 recover! dynamically allocated array does not seem to work

Hope all is well. This is probably a stupid question but I am going to ask it anyway. I have finally finished Recover (PSET4). I initially dynamically allocated an array as follows to store my 512 ...
0
votes
1answer
1k views

Finding & printing character after space in string in C

I've been banging my head against a wall here for days, trying to print initials after user name input. The errors change continually and are many. I'm trying to name the string array 'name' then ...
0
votes
1answer
32 views

Having some issues understanding how pointers work and how to pass them to functions and use them

int* create_random_array(int n){ int arr[n]; srand(0); for (int i = 0; i < n; i++) { // Fill with random ints 1-100 arr[i] = (rand() % 100)+1; } return arr;...
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 ...
1
vote
1answer
77 views

Pset7 - Portfolio: $positions not filling

Working within index.php, I feel like I understand the logic of what is going on, and I can get portfolio.php to render out fine on the website - with the exception that it only prints out one row ...
0
votes
1answer
910 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
145 views

PSET 4 Resize: Pointers, arrays and file IO

Stuck on PSET4 resize: the file I'm writing is going into overflow and I'm not sure why. I've designed it using nested for loops as you'll see. It compiles and runs, but then it says the file is too ...
0
votes
0answers
115 views

Why can't I create an array of strings?

I have this habit of first trying out all the exercises of the book then going on to psets. I am on chapter 7, arrays. the question was to make a program of some sort of voting counter and instead of ...
0
votes
1answer
23 views

Clarification regarding for loops and arrays

In the continued lecture of week2: At about 17:00 he writes the for loop. What does i stand for? I don't think it is age, but it can't be the number of students? What does it mean? What is ages[i]? ...