PO
prog will start corectly
Nils
You can get the position of the file name extension via strlen()
Nils
Just find the end of the file name and decrease the pointer by the lengh of the file format.
Nils
Then check if the resulting pointer is lower than the file name pointer to avoid undefined behavior
Nils
And then compare the resulting string with the file format string.
PO
the problem is the filename isn't always the same
Nils
So basically... char *file_name_ext = (file_name + strlen(file_name) - strlen(file_format)) if (file_name_ext < file_name) { ... error } else if (!strcmp(file_name_ext, file_format) { ... error }
Nils
I hope I have no typos 😅
PO
PO
@PO_uria
int main(int argc, char *argv[]) { char *optstring = "h::f::"; char *file_format; char *filename; int val; while((val = getopt(argc, argv, optstring)) != EOF){ switch(val){ case 'h': printf("Please Enter : -f <file_format> <file_name> \n \n"); break; case 'f': file_format = argv[2]; filename = argv[3]; break; } } if(!(filename && file_format == NULL)){ printf("You have entred : %s <file_format> \n\n", file_format);//Command_line_check printf("You have entred : %s <file_name>\n\n", filename);//Command_line_check }else{ printf("Please Enter : -f <file_format> <file_name> \n \n"); } PNM* image; if(!(filename && file_format == NULL)){ load_pnm(&image, filename); write_pnm(image, filename); } printf("End of program\n \n"); return 0; }
PO
@PO_uria
Thank you, I'm going to try
PO
?
LostInNeonCity
Hello , please can you recommend me courses to learn data structures in c
LostInNeonCity
Try implementing a hash map
I will try cuz i get nothing from youtube courses , i need new resources
ronaldo
Hey
Mandelbröt
I have n points in a 2d plane .... and i have to make a convex polygon of minimum area every time when i m allowed to remove one of the n points
Nils
I can't undrestand why ( file_name + strlen(file_name)(file_format))
You take the pointer to the file name, move to its end and decrement by the length of file_format
PO
thank you
PO
👌
the only things I'm not sure if I've understood is (file_name + strlen(file_name))
PO
But I'm trying
Anonymous
Anonymous
Hello. Someone know why I see this yellow mark in this function in Clion IDE ?
Pavel
Maybe you've typed "fill_" into the search? Try pressing Ctrl+F
Indolent
In the simplest possible langauge what's the difference between * and &
Indolent
like in the terms of a function especially
Indolent
int doSomething(int *data1, int *data2)
Indolent
return data1 + data2
Pavel
In the simplest possible langauge what's the difference between * and &
1) & assigned once when it's initialized and can't be reassigned 2) & can't point to nullptr 3) * uses -> for dereferencing & uses .
Pavel
return data1 + data2
Ok, also in this case you trying to sum two addresses, not values. You can sum values by *data1 + *data2
Indolent
Yes
Indolent
now in the main function if I call doSomething (what1, what2); What should be the data types of what1 and what2?
Indolent
(when I pass & there is no output but it compiles)
Pavel
Indolent
That gives no output. Can you make working example for me on pastebin?
Indolent
It's absolutely fine. It's a damn miracle that you even bothered.
Indolent
btw you could've used "rn" instead of "right now" :p
Pavel
btw you could've used "rn" instead of "right now" :p
I decided that it's too much abbreviations in one place :)
Indolent
I pardon you.
Pavel
That gives no output. Can you make working example for me on pastebin?
That's what I meant (doSomethingPtr version) https://ideone.com/boVg9g Note that it's better to pass just int by value in this case. You usually want to pass non const reference or pointer when the function can change the original value. And passing by constant reference is usually used as 'optimization' to avoid copying big objects (e.g. std::string often being passed by const ref)
Indolent
You're a damn miracle.
Anonymous
Anyone here working with mpi ?
Anonymous
Okay, sure :) i have a wierd problem i have set up mpicc and everything needed to develop mpi applications and packed that in a vm image i distributed to some friends for easy use/setup. However whenever they try to compile their application the compiler tekks them that mpi.h could not be found. But it did work for me and should be part of the mpicc installation. So dont really get how that could happen.
Anonymous
will most likely end up creating another image later and tjat will most likely fix it. But im still curious to what could have caused that
PO
👌
It's working perfectly
PO
PO
how can I solve these warning?
I_Interface
how can I solve these warning?
Read the text and solve it, what's the problem ?
I_Interface
PO
Read the text and solve it, what's the problem ?
I can't understand why it shows me the first warning?
I_Interface
Dima
unused parameter
I_Interface
unused parameter
Thank you, my dear bot.
PO
But my teacher wrote the same shit
PO
I made a function which I call Destroyer
PO
To free up all memory which I had allocated
Pavel
But my teacher wrote the same shit
He probably disabled this warning in his IDE or via compiler parameters
PO
How do you free up 2 dimensions array?!
PO
static void destroy(unsigned int **destroyer, unsigned int raw, unsigned int column){ if(!(destroyer)){ return; } for(unsigned int i = 0; i < raw; i++){ free (destroyer[i]); } free(destroyer); }
PO
I can't understand why when I use this function I get Segmentation fault?
PO
static void remove_comment(char* line, FILE *opf, PNM *a){ if(strstr(line, "#") != NULL){ printf("There is a comment line \n \n"); comment(opf, a); }else{ printf("Program processing . . . \n \n"); int array = sizeof(line); fseek(opf, -array, SEEK_CUR); } }
PO
please help
Alex
But my teacher wrote the same shit
google for attribute unused in your compiler, or add (void) column
PO
google for attribute unused in your compiler, or add (void) column
okay, and my function will do the job? I mean free up the memory?
Alex
behavior of the function will be the same. its just to supress compiler warning