Anyone good at C Programming? I totally need help writing a code for a problem

Anyone good at C Programming? I totally need help writing a code for a problem.

why dont you post the code and one of the big guys will help you.

No, but, if you need help writing a problem for a code, I'm your man.

I am not sure where to start. I have written a few codes before, but I am so lost where to even begin with the ones I have.
Yes definitely! I'm going to post the problem here in just a minute

how one can create dynamic array of char* using realloc()?

I need to write a program using input and output files with the names lab6p1.in and lab6p2.out.

As part of my solution, I need to write and call the function "leap()".

Question the program needs answered is "The year 1900 is not a leap year, whereas the year 2000 is a leap year. Why?"

The input file (lab6p1.in) will have three integers which are 6 26 and 2000.

Output file needs to contain the day, number, year (in a format similar to a|a|a or 02|28|1900)

I am about to post a code I've written that may give an idea of what I mean by some of this.

sent ;)

check your PMs

Having no luck, can't find :(

...

Here's an idea of what i
t's like. This the last one I did.

realloc() doesn't create anything
malloc does. Let's say you need a 10 chars array.
char *c = (char *)malloc(sizeof(char) * 10);

you get a pointer to your array.

if you want to change the size of said array, THEN use realloc();
char *c = (char *)realloc(c, 20);

don't forget to:
- clean/initialize your arrays prior to using them and
- use free() when you're done.

I meant to write
char *c = (char *)realloc(c, sizeof(char) * 20);

my bad.

What the fuck are you actually trying to do and what has it got to do with:
>"The year 1900 is not a leap year, whereas the year 2000 is a leap year. Why?"

It's worth noting that modern C doesn't require you to cast malloc's return value.

Think about the logic inside function leap(). How do you write a
condition to check if a year (an integer) is divisible by 4? By 100? By 400? For
which of these 3 conditions is a year “always” a leap year? For which of these 3
conditions is it “sometimes” a leap year?

Maybe I should choose another problem for help cause this one just seems too much

Ask the user for the number N (an integer) of real numbers in the set. Then ask for
each number, one at a time. Below is a sample run:


Statistics CalculatorInput N: 5
Input num: 71.7
Input num: 78.5
Input num: 80.9
Input num: 81.3
Input num: 77.4
Average = xxx.xxx
StanDev = yyy.yyy

>How do you write a
>condition to check if a year (an integer) is divisible by 4?
if((year % 4) == 0) { // it's divisible
} else { // it's not
}

...

it's also worth noting that
sizeof(char) * 20 and 20
are the same since sizeof(char) is 1.

Damn this is perfect. So for the divisibility we're using else if statements?

>since sizeof(char) is 1
What if we are going to use 16-bit encodings?

If the compiler you're using is C99 compliant, it's always 1.

From the C99 specs (regarding sizeof):
When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1.

Here is a screenshot of the way it was written out by the professor

...

Algorithm taken from wikipedia.
#include

int leap(int);

int main(int argc, char **argv) {
int year;

for(year = 1; year

>Windows 10 user
>Can't export as a single .png
Retardation checks out

Use dynamic predicates

you should always when you've decisions. it's the way to handle branching paths.

Awesome!

Well to be fair this is where I had it and I had a screen shot ready for a classmate I shared it with, plus who cares if I use 10? Does it bother you THAT much? How does it relate to C code when I don't use it on 10? Must be rough that your only contribution is the obvious.

Anyway, thank you all for helping me out, especially one user in specific for getting me the algorithm and stating to use else if statements.

Why doesn't this work?

long long int a = 600851475143;
long long int b = round(sqrt(a))

works on my machine

:|

I get pic related after compiling and running.

Also, when I put the number directly inside the functions, it works.

Did you include math?

idk how it works with your program but with my program when running and there's include then you have enter -lm at the end before compiling. That's usually what it means when it states undefined reference to sqrt

I'm taking a C class at a City College. I wish they did more than just teach the syntax. I read K&R before the class began, and now I'm about a month ahead of everyone else. I really wish we spent more time learning algorithms and less time writing stupid fucking conversion programs. This assignment is somewhat interesting, learning how to parse through HTML, mainly using strstr(). Please remember to like, comment, and subscribe to my blog desu

...

Yeah

Damn, that actually fixed it, thanks

y-you too

No problem!

btw, what does -lm do anyways?

Pretty much it just tells the program/compiler to compute specific mathematical formulas such ln, sqrt, pow, etc. but you don't need it when you use very basic math like addition, subtraction, etc.

ah ok, thanks

Why do you need to link to the math library anyway? Is it not part of the standard library?

no

These aren't mutually exclusive though. sizeof(char) is always 1, but CHAR_BIT could be 16.

>CHAR_BIT could be 16.
What? Why would someone do this? How common is this? I've always parsed files 1 char at a time under the assumption that it would be 8 bits.

>.exe
Why?

Why is it that when I try to free a region of memory after changing it via realloc I get a segfault?

Semicolon?

My guess is that you're freeing the wrong memory.
Post code snippet.

Too late, I turned in the assignment.

In short, I was trying to prepend a string to an array of strings. So I realloced the array to make room for one pointer,
Strcpy'd the strings after reallocating the memory each element of the array pointed to. Then setting array[0] to a specific string via strcpy.
Free(array[0]) broke. Claimed the pointer was invalid.

The weird thin was that it worked when the array was length 1 or 3, but not 2 or 4