hey guys, sorry but i gotta ask someone, google isn't really helping.
why do i get "error: conflicting types for 'fgets'"?
hey guys, sorry but i gotta ask someone, google isn't really helping.
why do i get "error: conflicting types for 'fgets'"?
Other urls found in this thread:
What are you trying to do?
why are you using a char with fgets? wouldn't it require a string?
fgets is declared as:
char *fgets(char* s, int size, FILE *stream);
Notice the first argument is a char*, not a char.
Go to cucks overflow
i just want to read the first line of the file and put it in 'zeile'
also, is it possible to put different parts of the same line in different variables?
infact, wtf are you trying to do with
char *fgets?
You've just redefined "fgets" which is already a function.
replace
>char *fgets(char zeile, int n, FILE* fp);
with just
>fgets(zeile, n, *fp);
also in the definition for zeile, change it to a char pointer rather than just a single char
>char zeile;
to
>char* zeile;
more or less this
that actually made a difference, thanks. now i only get the error in line 34
nigga you re-prototyping the function in main
char zeile[100];
int n = 100;
...
fgets(zeile, n, fp);
shouldn't he also allocate memory for zeile?
This If you're not trying to redeclare it, this isn't what you should be doing.
why use c, comrade? use python or something
> inb4 brainlet
THE GERMANS ARE TRYING TO PROGRAM! THEY GONNA NUKE US ALL WITH THEIR BUGS!
You included the wrong header, it's
#include
Honestly this looks like a pretty standard assignment you'd get in a university course, so it's probably for a module they're doing
i don't do this for fun, this is for university and this shit is due tomorrow
You forgot to #include
EPIC troll dude
tried it, got this
my condolences, comrade. I too have an exam on C the dat after tomorrow.
>complaining about having to do a 50 line c program until tomorrow
nibba, I have to make a database for a library, a web interface the database and like a 40 page documentation, all until midnight
whoops, missed this. You're dereferencing the file pointer.
Replace
>fgets(zeile,n,*fp)
with
>fgets(zeile,n,fp)
my bad!
Don't dereference fp. Replace *fp with fp
why would you need a pointer to a 2D array!
not complaining, just saying it has to be done
Also, homie I'm gonna say, maybe look up a quick tutorial on C programming. I messed up without testing, but this problem should have been easily spotted from picrelated.
C is pretty easy, there's not much to it, I'm sure there's tuts online that cover exactly what you're trying to do
>char name[30];
>daten[10]
>namezeile[20]
Fucking stop with this shit.
>Deepin
>Doesn't actually use Deepin OS but the screenshot/screenrecord tool is really good
what exactly? the names? defined length?
>chinese botnet
>it's a screenshot tool
>name a better one
>no seriously please
>i'd actually appreciate that
Arbitrary array sizes, this is bad practice. Take it for future reference - for handling names you want proper buffered subroutines that return malloc'd names. For general arrays, define a global macro instead of having magic numbers here and there and hoping to remember them.
scrot
yes it has a selection box
scrot
Take a look at the errors the dude is making and tell me OP's ready for that kinda crap.
Arbitrary array sizes are dogshit but so is this programmer for the time being. Maybe in future OP will actually read a book
which book would you recommend comrade
The C programming language by K&R
okay, i'm error free now. now i just need to know how to pick a specific line and column
this is what my input files look like, can have more or less columns
K&R, the C programming language. obvious, but the best introductory text. it's pretty short!
OP here, i use puush
takes a pic, uploads it and copies the link to your clipboard
Not him but the C programming language. The one with the fat red ANSI C stamp. That's all you need and just keep to the basics. Forget about function pointers, variadic function arguments, macro metaprogramming, and all that niggerlicious crap.
Just read the basic shit and move on to C traps and pitfalls by AT&T (great little book).
Also can you just post a pastebin of your current source code and compile errors? And what the exercise is?
>zeile
>namezeile
>daten
This triggers me.
it just needs to work. this is not a week long project where nomenclature is not an issue
Also can you just post a pastebin of your current source code and compile errors? And what the exercise is?
>Not writing in COBOL
What's the matter, too hard for you?
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZ-BUZZ.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CT PIC 999 VALUE 1.
01 FZ PIC 999 VALUE 1.
01 BZ PIC 999 VALUE 1.
PROCEDURE DIVISION.
FIZZ-BUZZ-MAIN SECTION.
PERFORM 100 TIMES
IF FZ = 3
THEN IF BZ = 5
THEN DISPLAY "FizzBuzz"
COMPUTE BZ = 0
ELSE DISPLAY "Fizz"
END-IF
COMPUTE FZ = 0
ELSE IF BZ = 5
THEN DISPLAY "Buzz"
COMPUTE BZ = 0
ELSE
DISPLAY CT
END-IF
END-IF
ADD 1 TO CT
ADD 1 TO FZ
ADD 1 TO BZ
END-PERFORM
STOP RUN.
Literally 80% of that is cobol-specific syntax, what a piece of trash
that shits outdated nigga
Ah yes because C has evolved so much
not op but my professor explicitly advised against this book as its too old.
true true. I'll give it a try
>Not writing in x86 assembly
What's the matter, too hard for you?
global _start
extern printf
extern sprintf
extern puts
extern exit
section .text
_start:
mov ebp, esp
mov esi, 0x1
xor edi, edi
jmp .fizz
.fnum db '%d', 0Ah, 0
.fizzStr db 'Fizz', 0
.buzzStr db 'Buzz', 0
.nl db 0Ah, 0
.loop:
cmp edi, 0x1
je .printnl
jmp .back
.printnl:
push .nl
call printf
jmp .cont
.back:
push esi
push .fnum
call printf
.cont:
add esp, 0xc
add esi, 1
cmp esi, 0x64
jle .fizz
mov edi, 0x0
push 0x0
call exit
.fizz:
mov edi, 0x0
call .check3
.buzz:
call .check5
jmp .loop
.check3:
mov edx, 0x0
mov eax, esi
mov ecx, 0x3
idiv ecx
cmp edx, 0x0
jne .buzz
mov ecx, .fizzStr
call print
jmp .buzz
.check5:
mov edx, 0x0
mov eax, esi
mov ecx, 0x5
idiv ecx
cmp edx, 0x0
jne .loop
mov ecx, .buzzStr
call print
jmp .loop
print:
mov ebp, esp
push ebp
mov edi, 0x1
mov eax, 0x4
mov ebx, 0x1
mov edx, 0x5
int 0x80
leave
ret
Sure but it still feels wrong and I've seen quite some tools which started as a one off script and a year later i have to extend it and everything is fucking french.
> by H&K
>its too old
You may need C99 once or twice in your life. C11 you will never need. That's all you need lad. Nobody writes shit in C anymoe anyways, the whole language is a fairy tale of trust and wishful thinking.
vPp6VBVj
also i get segmentation fault from the loop in line 35
sorry forgot the assignment
basically there are files with measurement data and the program is supposed to create a new file and put min/max/avg of the values in it
Just used it for a little bit, it's fine but it doesn't work with xfce's keyboard shortcuts, also i like deepin screenshot's option to save to clipboard.
This idiocy demonstrated in this thread is physically hurting me
Bow you understand why the autists here hate C
They are too stupid to use it
instead of complaining about nobody understanding C you could just help me. the code you see here is all i have ever written in C and i don't know ass about pointers. i only worked with C++ and C# before.
>doesn't know ass about pointers
>used C++ before
how
I'll look at it
teachers said they are shit and we are not to use them. period.
lern erstmal programmieren brudi
>German education
Holy fuck
sure, smart pointers are a much better idea, but I guess they didn't even mention that
What shit uni do you go to, user?
Oh wow your uni is fucking trash
/thread
Stupid questions thread.
Fachinformatiker?
Are you retarded, OP?
Hoffentlich nicht
war im fachabi, die haben gemeint für unsere zwecke brauchen wir die nicht.
Hang in there OP I'm writing it. I've only ever written C++ but I hope it will at least compile.
Also I assume your file input is a big row of doubles.
this is what my file looks like, its just text
first row: number of columns
second row: name of measured property
third row: unit of measured property
fourth row: frequency at which unit was measured
Sorry OP this is the best I could do.
The rest is just how to format your input to read columns instead of rows or shit like that. It should be trivial.
Compiled on MSVC.
Tell me what you think or if It don't work.
I made it to read a row of numbers, but fscanf automatically skips tabulations, spaces, and newlines.
Wow yikes actually line 23:
if (!strcmp(file_path, "n"))
break;
You're welcome and have fun
thank you very much
it does compile, but output is empty and it kinda freezes after i give it a filename
okay, with that change it just crashes the moment i give it a file, no error message though
My setup:
I put a text file (say hmm.txt) right next to my main.c file.
At the prompt, I write hmm.txt and there should be just that in the file_path variable. You should be able to write an absolute path (use / as separator) and put the file anywhere you have user access to.
What IDE you on? Set a breakpoint and step into that code.
i read it and it makes sense to me, i did the same thing with my files.
the problem is your code looks like its myde for files with just one column, but i have files with three and ten of those, and every column needs to be calculated separately
i use codeblocks
Oh by the way, my routine reads floats only. Make sure you're skipping over the text stuff.
you can make your own
void fignore(size_t how_many)
{
while(how_many--)
{
getchar();
}
}
or just use fscanf(source, "%*[^\n]\n", NULL); but that's regex and magic to me.
Yes it reads a line of numbers. Ah, you want to read the whole column and write out min/avg/max.
Well then make float curr[3]; That's a value for each column and get each via next_data().
As in for( int idx = 0; idx < 3; ++idx)
curr[idx] = next_data(source);
Then just apply that min/max/avg logic but vertically, for each curr[].
Look this may seem hard but i'm trying to weasel my way out of using matrices. You can definitely make your own large ass matrix and fill it, but that's a waste of space in my mind.
Oh also that's void fignore(size_t how_many, FILE* source)
{
while(how_many--)
{
fgetc(source);
}
}
i thought about a huge matrix, but thats bullshit. i dont need to save every value all the time just to save three values.
the problem is, i need the output file to contain the text at the beginning, its supposed to be a table, like this
what exactly am i solving with this and where do i put it?
also i tried it with files without text and it still crashes with an empty output file
The idea is, you have Druck, Temperatur, and Drehzahl, right?
So you have float curr[3] which signifies the current units of each measurement type.
So for each current measurement, you need a separate avg, elem_cnt, min, max. At each step, add the current measurement to its respective sum, refresh the respective min and max, and increment the respective elem_cnt.
As far as printing goes, you have to fprintf Druck, then its elem_cnt, then the min, max, avg.
Then fprint Temperatur, etc
You have all the variables you need.
In case you need to skip over a number of chars in a file, aka non-floats.
For me, with an empty file, it just prints
min: 0.000000, max: 0.000000, avg: 0.000000
I see a problem in case you have an arbitrary number of measurements aka columns. That would require dynamic memory allocation and making a variable to save each measurement name.
What I can see right now is
struct Measurement
{
char name[256];
float min, max, sum;
size_t elem_cnt;
}
Then just make a dynamically allocated array of these structures.
Separate the min/max/avg/sum crap into a function
void refresh(struct Measurement* target, float currData);
It updates min/max/sum/elem_cnt. Later when you need the average, compute it on the spot via sum and elem_cnt.
Of course, when you read each measurement name from the second line of the file, you update each struct's name.
This is all I can do right now, I have some MATLAB swamp to tread. I have no idea why it crashes with you and I can't use a debugger instead of you.
I'l stick around for a few more minutes.
>scanf with no size limit
B U F F E R O V E R F L O W
this is actually very good advice, thank you
but why is it crashing with a file without any text and just numbers?
I don't know why it's crashing, It's not crashing on MSVC's implementation of C libraries. Sorry friend.
Sorry, don't care. I'd be using a better language if I did.
What's wrong Rajesh, can't shitoverflow into you solution?. Fucking kill yourself, brainlet.
Learn to use a debugger, newfriend
Wait lol try entering n as in the symbol n instead of 'n'
the build gives me zero errors, so debugger is grayed out. it crashes like "test.exe stopped working"
test.exe stopped working