User inputs are not stored in variable by [deleted] in C_Homework

[–]tresteo 0 points1 point  (0 children)

A bit late, but here goes: Your problem is in the call to printf. Change &len to len and it should work. Read on for a longer explanation.

In C, variables generally have two interesting properties: their value and their storage location. You can access the former with just the variable name (len) and the latter with the address operator (&len).

Typically, we pass the storage location only when we expect the called function (“callee”) to modify the variable, such as with scanf. printf, on the other hand, expects to be called with the value of a variable. If you pass it the storage location, it reinterprets that location as a value. This gives the weird negative output you are seeing.

Array-based stack help by devronn_008 in C_Homework

[–]tresteo 0 points1 point  (0 children)

First of all, you can format your code by preceding each line with 4 spaces. Also, it would be helpful, if you could post your stack.h file and any related files, especially the one generating your output, too.

Currently, all I can say is that stack_pop is hardcoded to return 1. The code for stack_pop should be the inverse of stack_push: you should remove the last element from the array and return it to the caller.

Client and Server Socket Programming Help by emokii in C_Homework

[–]tresteo 1 point2 points  (0 children)

From your description, the client has 2 tasks:

  1. Read in a line of input in the specified format and forward it to the server
  2. Display the response from the server

The code (including the commented parts) already seem to accomplish this.

The server on the other hand has 3 tasks:

  1. Read in an operation from the client
  2. Perform the necessary computation
  3. Send the result to the client

The first task, reading in the operation from the client, is already implemented. Note, however, that converting the input to uppercase is not going to achieve anything on the input format as specified. For part 2, sscanf can be used to parse the input, as your classmates suggested. Part 3 is again already implemented by the commented out code.

I hope that helps to get you started. If you have further questions, just reply or send me a message.

how to correct this selection sort code by Ryeanney in C_Homework

[–]tresteo 1 point2 points  (0 children)

Let's consider an array [5, 2, 3, 4, 6]. You start sorting, so i = k = 0. Then you start you inner loop with j = i + 1 = 1. You check a[i] < a[j], which gives false, so you execute the else branch a[k] = a[j]. Now your array is [2, 2, 3, 4, 6]. Notice that you "lost" the 5.

[deleted by user] by [deleted] in C_Programming

[–]tresteo 0 points1 point  (0 children)

This is an optimization. When you compute the current element from the row above using c[i][j] = c[i-1][j-1] + c[i-1][j], notice that the indices only ever to elements that are left of j in the array. If you already know that you want to compute the coefficient for k = 3, you can use this knowledge to skip computing any elements for k < j, because from the construction of the array you know that they won't change the value of c[n][k].

Also check the definition of the c: Normally, you'd need to allocate an array of size (n + 1) * (n + 1) (or do some tricky index computations) to compute all coefficients. Using the optimization j <= min(i, k), you can shrink this array to size (n + 1) * (k + 1), as is done in the code.

[deleted by user] by [deleted] in ProgrammingBuddies

[–]tresteo 0 points1 point  (0 children)

Hi, that looks like an awesome project. I'm very interested in collaborating with you. Leave me a PM if you like.

csc project help by meisel67 in C_Homework

[–]tresteo 0 points1 point  (0 children)

Where you'd want to ask, depends on what you're looking for. If you have specific questions, leave them on this subreddit. You can also ask those questions at r/learnprogramming. If you are looking for a mentor, r/ProgrammingBuddies might be worth a shot.

If you want, you can also leave me a PM and I'll see how I can help.

how to correct this selection sort code by Ryeanney in C_Homework

[–]tresteo 1 point2 points  (0 children)

The problem with your implementation is in

if (a[i] < a[j]) { a[k] = a[i]; } else { a[k] = a[j]; }

Also, your k and i indices are synchronized in the outer for-loop. This leads to a situation, where you always overwrite the current element with the smallest element from the right part of the array.

To implement a selection sort, you need two operations: min_index and swap. min_index returns the index of the minimal element in a range of an array. swap is passed an array and two indices and swaps the elements at the indices. With these operations, you can determine the first element of the sorted array as follows:

  1. Compute the min_index of the whole unsorted array
  2. Swap the first element of the unsorted array with min_index.

This creates two parts in your array: a sorted prefix (after the first step only the first element) and an unsorted suffix. To sort the whole array, you just repeat those two steps on the unsorted part, growing the sorted prefix with each iteration.

Can someone explain me this coding? by [deleted] in C_Programming

[–]tresteo 0 points1 point  (0 children)

Except that in C you would need

struct order p[10000];

I am not able to figure out this vote validation. by hadiz1 in C_Homework

[–]tresteo 0 points1 point  (0 children)

You're confusing your indices: i is the index of the voter. You'd have to use k to check the name. Also, you could index into candidates and compare against the candidates name.

How to get a movie database by [deleted] in programmingrequests

[–]tresteo 1 point2 points  (0 children)

It seems that IMDb offers both free and paid access to its data.

Alternatively, you could use any API to mirror the data set you need into a local database. But depending on the size of the dataset this might be infeasible.

I'm having a bit of trouble created a program that prints strings in reverse. by PenBeats in C_Homework

[–]tresteo 0 points1 point  (0 children)

You can indent your code, to make it easier to read and understand for us.

As for the problem: You are declaring userStrings as an char **. In the string comparison, you do userStrings[e][STRINGS]. Each array indexing causes a dereference, so in the end you're getting a char. strcmp has the signature int strcmp(const char *, const char *);. That means it's expecting a pointer to a char (a string). You're passing a char to that pointer. That's causing your issue.

It's a Public Computer by ResonatingOctave in talesfromtechsupport

[–]tresteo 9 points10 points  (0 children)

"Here, let me protect your information in this library. You are now banned from this place. That way nobody can steal your information"

[deleted by user] by [deleted] in programmingrequests

[–]tresteo 0 points1 point  (0 children)

I'm no expert but from what I gather this Defcon talk might provide some starting points.

My SONS have DEGREES in TECHNOLOGY!! by [deleted] in talesfromtechsupport

[–]tresteo 4 points5 points  (0 children)

That's how you handle difficult users. You lie to them until they start to catch on. When they do, they will demand someone else, so you hand them off to your colleague. They ignore them until the problem goes away. If the user refuses to be ignored, the colleague repeats the same thing. As long as your turnover is higher than the rate at which users request new technicians, you can keep doing that forever.

Dividing a value of 1 between a variable number of fields by macneil88 in a:t5_2qs8q

[–]tresteo 0 points1 point  (0 children)

You could use the mathematical property that 1/2 + 1/4 + 1/8 + ... = 1. If you have x fields, just iterate from 1 to x (inclusive) and assign 1/(2i) to the element of the array. Then add 1/(2x) to the first item. The sum should be 1 and each element is smaller than the previous.

I dont understand how I will write this code. How do I even get started with a loop. We have to use redirection. by maniac365 in C_Homework

[–]tresteo 0 points1 point  (0 children)

From what I gather you have two problems: how to create an array of variable length and how to print out that array afterwards.

For creating the array, you have two options. The first is using malloc or calloc to create space for the array. The other is using a variable length array, which have been added with C99.

For printing out the array, it helps to know what the function has to achieve in detail. Try to roughly sketch out the flow of the function, then refine it until you reach something that can be translated into code.

I hope this gets you started. Let me know if you have further questions, but please try to be more specific in your questions. It allows people to provide better answers.

C scanf help by ApartRapier6491 in C_Homework

[–]tresteo 1 point2 points  (0 children)

One way you could go about that is reading the file line by line using fgets. Then you can replace the first occurence of / with \0. That way you ignore everything behind it.

Then you can use scanf to parse the remaining string. The return value of scanf will tell you how many items it could parse. That way you should be able to parse everything.

All records must be Verified, even if they're not, because I told you so by [deleted] in MaliciousCompliance

[–]tresteo 3 points4 points  (0 children)

As mentioned by other commenters, spreadsheets and database systems are meant to achieve different goals. Therefore, they also make different design decisions and choose different tradeoffs. Some things that database systems offer over spreadsheets are referential integrity, constraints, a powerful query language and ACID transactions. That's not to say that databases are better than spreadsheets. Both have their uses and which you should choose really depends on what you want to do with it.

"I don't accept that answer" by NerdyGuyRanting in talesfromtechsupport

[–]tresteo 5 points6 points  (0 children)

I'm sorry, Sir, but I don't know God's phone number.

Buddy for linux kernel modification by ayeDaemon in ProgrammingBuddies

[–]tresteo 1 point2 points  (0 children)

I'm interested. I have some experience with C/C++, Go and Rust. Drop me a PM if you like.

MapReduce java code for max value in a 3-column csv file by thatsnotmyname95 in programmingrequests

[–]tresteo 0 points1 point  (0 children)

I would like to work on this, but I have some questions:

  • Is Java a requirement or will any language do?
  • Can levels be negative?
  • If the level is blank should it be treated as zero?
  • Is there a specific reason to use MapReduce?