Anonymous
c is a nice language
C.
line 16: a ';' that is not needed ArrayLenght is sizeof(array)/sizeof(arrayType)
Anonymous
int arrayLength = (sizeof(track[0])/sizeof(char))*3;
dont i need the length to know when to end the loop?
I_Interface
dont i need the length to know when to end the loop?
U need to know a num of elements if you want to work with array
Anonymous
the array is two dimensional , which holds a list of strings with the max of 80 characters, so the length would be the size of the array /80 since char only take up 1 byte
Anonymous
U need to know a num of elements if you want to work with array
what if the number of elements change? dont u need some way to change with the program
I_Interface
2-D array size = rows * colums.
I_Interface
Anonymous
https://pastebin.com/ArbwLYJD
Anonymous
take a look at the code
C.
line 16
C.
there is a rogue ';'
Anonymous
there is a rogue ';'
i change that , but i think the main issue is else where
Anonymous
Humbles-MacBook-Pro:Chaptertwofive humblerise$ gcc tracklist.c -o track && ./track What Track are you looking for? Digital
Anonymous
when i compile , after i put in the input, the program ends
Anonymous
so the function itself is not working
C.
so the function itself is not working
put some testing printfs in all the program and see where it stops working
C.
OOOOOH found the error
C.
if (strstr (track[counter], CompareTrack) != NULL)
C.
Pointers are not valid to use in if statements. They never give a true or false, as they're not numbers.
Anonymous
huh pretty sure NULL is falsy and all other pointers truthy
C.
Did it wprk?
C.
huh pretty sure NULL is falsy and all other pointers truthy
Nopey. they're always or falsy ot truthy
Anonymous
I'm pretty much 100% sure only NULL is falsy
Anonymous
Did it wprk?
not at all lmao
Anonymous
comparisons like if (!pointer) ... is pretty common after memory allocation to test if it failed
Anonymous
so if definitely somewhere in the if statement
Anonymous
Ибраги́м
Don't do this @ work!
C.
Pop into my oven! https://gcc.godbolt.org/z/NJWtzu
If you do not point at null, it'll always point somewhere, that can or not be NULL
C.
So u think u are clever now huh?!
just take out the first comparison and see for yourself.
Ибраги́м
C.
just take out the first comparison and see for yourself.
Anonymous
lol you didn't remember to strip the newline from fgets
Anonymous
that was why the comparison always failed, do that then your program will work correctly
Anonymous
that was why the comparison always failed, do that then your program will work correctly
just tried it with scanf, worked like a charm lol but the book wants me to use fgets
Anonymous
you can use fgets you just need to replace the \n at the end with \0
Anonymous
Anonymous
yeah, it doesn't return the number of characters read so you'll have to loop to find the \n
Anonymous
#include <stdio.h> #include <string.h> char track[][80] = {"Digital Dash","Cold Winter","Cruel Summer","The Cool","twenty two 2s"}; // track takes up 80 bytes for each string, so 400 with 5 elements void find_track(char *CompareTrack){ int arrayLength = (sizeof(track)/80); for(int counter = 0; counter < arrayLength;counter++){ if(strstr(track[counter], CompareTrack)){ printf("%s is in Our PlayList!\n", track[counter]); } } } int main(){ char inputTrack[80]; puts("What Track are you looking for?"); fgets(inputTrack, 80, stdin); for(int i = 0; i < 80; i++){ if(inputTrack[i] == '\n'){ inputTrack[i] = '\0'; break; } } find_track(inputTrack); return 0; }
Anonymous
this is the final product , works now
Lionel
A quick question. The register variables can be stored in cpu registers and stacks or cpu registers alone?
Abhinav
/rules
olli
A quick question. The register variables can be stored in cpu registers and stacks or cpu registers alone?
What do you mean by register variable? The keyword is no longer valid c++ and was meant to be a hint for the compiler. In C it is still a hint to the compiler to store the variable in a cpu register, that can be freely ignored. Additionally you cannot get the address of it.
Pete
Are there ever times where you’re like, why am I doing this? It’s so time consuming and confusing at times
Ilya
A quick question. The register variables can be stored in cpu registers and stacks or cpu registers alone?
register is now fully synonymous for auto, variables of both classes can be stored either in a register or in the stack memory.
Ибраги́м
https://gcc.gnu.org/gcc-9/changes.html
Anonymous
A quick question. The register variables can be stored in cpu registers and stacks or cpu registers alone?
In modern C++, the keyword register was removed as storage class specifier, but it's still reserved
Praneeth
Every node in the linked list will have a number. Find out if the linked list nodes can be part of a febonnacci series. Retain the nodes that are part of the series and delete thsoe those which are not.. Guys plss help me out with febonnacci function... To remove those which are not part of
Praneeth
No dude like algorithm....
Mat
No dude like algorithm....
Do you know the Fibonacci algorithm?
Praneeth
Yep
Mat
Yep
Well, you've all the instrument 🤔 for every member of the list, you need to know if the Fibonacci algorithm will provide that number, too
Praneeth
Dear admin... I cant figure out the logic hw to pass the ll to Feb function
Anonymous
ll?
Linked list
Mat
Dear admin... I cant figure out the logic hw to pass the ll to Feb function
You don't have to pass it to the Fibonacci algorithm. You have to have a function that does the comparison
olli
Register in C.
As being said: "In C it is still a hint to the compiler to store the variable in a cpu register, that can be freely ignored. Additionally you cannot get the address of it."
Lionel
👍
MᏫᎻᎯᎷᎷᎬᎠ
Again, it always depends on the compiler.
I think he meant that what if the compiler said "yeah, okay this var can be stored in the register" but after the compilation there come a run-time decision that all the cpu registers are full!!
MᏫᎻᎯᎷᎷᎬᎠ
Okay, I'm just stating what his real question was