Anonymous
but that function also takes another function as an argument
olli
question is it possible to pass a function pointer to a function , but that function pointer points to a function that also takes a function pointer as a parameter
yes - like this? typedef void*(fn)(void*); typedef void*(fn2)(fn*); void* bar(void *) { return 0; } void foo(fn2 func) { func(bar); }
olli
so fn2 is basically void * (func)(void*(*)(void*)) (better to use typedefs)
Anonymous
#include <stdio.h> int nums(); int add_third_num(); void printnums( int(*add_third_numP)( int(*numsP)(void) ) ); int main(int argc, char const *argv[]) { printnums(add_third_num(nums)); return 0; } int nums(){ int first, second; puts("Enter two numbers"); scanf("%i %i", first, second); return first + second; } int add_third_num(int(*numsP)(void)){ int second; int firsttwo = numsP(); puts("Enter two numbers"); scanf("%i ", second); return firsttwo + second; } void printnums( int(*add_third_numP)( int(*numsP)(void) ) ){ int answer = add_third_numP(numsP); printf("your answer is %i", answer); }
Anonymous
but i realize this syntax is wrong
Anonymous
yes - like this? typedef void*(fn)(void*); typedef void*(fn2)(fn*); void* bar(void *) { return 0; } void foo(fn2 func) { func(bar); }
#include <stdio.h> typedef int(*numsP)(void); typedef int(*add_third_numP)(numsP); int nums(); int add_third_num(numsP Funclong); void print_answer(add_third_numP Funk); int main(int argc, char const *argv[]) { print_answer(add_third_num); ; return 0; } int nums(){ int first, second, third; puts("Enter two numbers"); scanf("%i %i", &first, &second); third = first + second; return third; } int add_third_num(numsP Funclong){ int firsttwo = Funclong(); int new; int final; puts("Enter one more numbers"); scanf("%i", &new);; final = new + firsttwo; return final; } void print_answer(add_third_numP Funk){ int final = Funk(nums); printf("%i", final); }
Anonymous
i fixed it now
Anonymous
using typedef function pointers, your the man @ollirz
Anonymous
/ban
Anonymous
Why ?
rex
#include <stdio.h> #include <string.h> int main() { char s1[] = "Beauty is in the eye of the beholder"; char s2[] = "the"; char s3[]= "not"; int n = 0; int m = 0; int t = 0; int len = strlen(s2); int l=strlen(s3); while(s1[n] != '\0') { if(s1[n] == s2[m]) { while(s1[n] == s2[m] && s1[n] !='\0') { n++; m++; } if(m == len && (s1[n] == ' ' || s1[n] == '\0')) { t=n; while(s1[t]!=' ') { s1[t]=s3[l]; t--; n--; } } } else { while(s1[n] != ' ') { n++; if(s1[n] == '\0') break; } } n++; m=0; } printf(" %s ", s1); return 0; }
rex
tell me any correction i need to do in this in programme
rex
after compiling the programme this gives the output:——"Beauty is in the eye of the beholder'"
rex
i want to copy "not" in place of "the"
Ricardo
Guys, the console size on win10 is larger than its on win7, how can i fix it ? , tks
n1coc4cola
Augmented
hi friends, i have a 23bit wide angluar value in degress 0-360... 1^23=360.000 DEG, it is stored in as integer in uint32 (right justified)... if i multiply by 360UL... and shift the result right 23 times the that would be the whole part 0-359 degrees..., how can I easily get the remainder calculated, without using 64bit registers, and floating point variables... i need it formated as XXX.YYY, wehre XXX=0..359, YYY=000..999
Augmented
// d23 is the input value uint16_t whole = (d23 * 360UL) >> 23; uint16_t fract = (((uint64_t)d23 * 360000ULL) >> 23) - (whole * 1000); I need to ged rid of the 64 bit variable promoting and without using float...
Augmented
why do you need to get rid of the 64 bit variable?
it's for an 8bit mcu, so 64bit operations are quite machine time exhaustive, if i use assembler no problem, i can fit the arithmetic in 40 or 48bits using fixed point representation... but i want the code to stay portable, and use C only... these 23 bits input are read from an absolute encoder, it has a disc with gray code encoded angular positions... separating one revolution on 2^23 sectors... i need to represent it in degrees as whole 0-359... and fractional part in 1/1000 with 3 digits
Augmented
the 23bit input is right justified, but can be left as well if this helps... but then mutliplying with 360UL will not fit 32bit
Anonymous
hi,every
Anonymous
one
Anonymous
😃😃😃😃
Anonymous
how do the prescaler in timer0 of pic18f4520 works??
Anonymous
Olli i need help
Anonymous
Can you help me
Anonymous
It seems only you can help me
Anonymous
Please bud
Anonymous
Please can i pm you?
Anonymous
@ollirz can i pm you?
Ilya
why Accsees can be denied because of what ?
Two main reasons for this error are application you are building is running at the moment (win) or you have no free disk space
Anonymous
Hello✋... My code on c++ is ignoring everything in the if statement can anyone help me ...
Anonymous
If else statment
Anonymous
Yes bro
Anonymous
If you can help with it I can send you the code via inbox
I_Interface
If you can help with it I can send you the code via inbox
Use pastebin.com and send a link for your code here.
Anonymous
Do I have to post the code
Augmented
so you can either change your logic so you don't multiply by 360000 but by some smaller number instead or check whether you are about to overflow and handle the result approrpriate
however, i found proper soultion, it's quite simple // input is in in23 uint32_t d360 = in23 * 360UL; // fits in 32 bits (unsigned multiply) uint16_t whole = d360 >> 23; // whole part properly calculated uint16_t fract = ((d360 & ((1UL << 23) - 1)) * 500) >> 22; // fractional must stay between 000...999
Augmented
the trick i've used is to multiply with 500 (instead of 1000) which fits 9 bits, and shift right one bit less to compensate..., and to mask-out the excess above 23 bits, (after multiplication with 360) - done once, result used two times
Ludovic 'Archivist'
the trick i've used is to multiply with 500 (instead of 1000) which fits 9 bits, and shift right one bit less to compensate..., and to mask-out the excess above 23 bits, (after multiplication with 360) - done once, result used two times
You should take a look at the ryuu algorithm for floating point to characters conversion, it is extremely efficient and you actually seem to borrow some of the ideas, basically it relies on cheating on the conversion using powers of five
Kenneth
hi guys how do i understand the inherrited class unpacking part? template <typename TIndex, typename... Ts> class tuple_imp; template <size_t... TIndices, typename... Ts> class tuple_imp<std::index_sequence<TIndices...>, Ts...> : public tuple_leaf<TIndices, Ts>... { protected: template <typename... TValueTypes> tuple_imp(TValueTypes&&... values) : tuple_leaf<TIndices, Ts>{std::forward<TValueTypes&&>(values)}... { } };
Anonymous
Hello guys
Dima
Welcome
Dhanrz
Can you suggest good framework or concept to find density of people in a canteen or room for college monitoring app . Or any other concept to make this
Anonymous
Olay
Anonymous
Hello
klimi
Anonymous
I'm a human but I can't remove this warning
Anonymous
..............
klimi
since you can write you are already verified
Anonymous
klimi
because you already clicked it
Anonymous
I have clicked it........
klimi
YES YOU HAVE!
Anonymous
Thank you
Anonymous
Can any one good at C++ help me...... My code on c++ is ignoring everything in the if statement if you can help I'll send the code via inbox
Anonymous
if i need to use a typedef for function pointers, and i have my program split into different files, like a header file with your structures,unions, enums, and function declarations, a main doc with you main function , and a function c file, that defines functions, where would i put the typedef function pointers
Anonymous
https://pastebin.com/2nKiYtUg
Anonymous
this is function.c and header file
Anonymous
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "functions.h" int main(int argc, char const *argv[]) { create_Array(choose_Array_Member_Amount); return 0; }
Anonymous
and this is main
Anonymous
depends, if the function pointers are part of an API you can put them in the same header as your function declarations.
i figured it out, it was the naming convention i used, it was conflicting somewhere
14•08
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "functions.h" int main(int argc, char const *argv[]) { create_Array(choose_Array_Member_Amount); return 0; }
Errors: source_file.c:4:23: fatal error: functions.h: No such file or directory compilation terminated. It was supposed #include<function.h>
Anonymous
Working weird 😂 ? How
i send you the new code
14•08
Ok
Anonymous
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "functions.h" int main(int argc, char const *argv[]) { create_Array(choose_Array_Member_Amount); return 0; }
Anonymous
thats the main doc
Anonymous
i send you the new code
typedef enum{DESCENDING,ASCENDING,ATOZ,ZTOA}Directionals; typedef enum{INTEGAR,STRING}StringorInt; typedef union{ int *intArray; char **stringArray; }ArrayCreator; typedef struct { int ArrayMemberTotal; ArrayCreator DataType; StringorInt StringorInt; Directionals Direction; int stringlength; }ArrayData; typedef StringorInt(*InitialQuestionP)(void); typedef ArrayData(*ArrayMemberTotalP)(InitialQuestionP); void clearScreen(void); StringorInt Initial_Questions(void); ArrayData choose_Array_Member_Amount(InitialQuestionP Choose); void create_Array(ArrayMemberTotalP Data); functions.h file
Anonymous
#include <stdio.h> #include "functions.h" #include <stdlib.h> #include <string.h> void clearScreen(void){ printf("\033[H\033[J"); } StringorInt Initial_Questions(void){ StartOverMyG : ; clearScreen(); char stringOrIntegarArrayChoice; puts("Do you want to create a String or an Integer Array?"); puts("Type I for an Integer Array or S for string Array"); scanf("%c", &stringOrIntegarArrayChoice); switch(stringOrIntegarArrayChoice){ case 'I': return INTEGAR; break; case 'S': return STRING; break; default: goto StartOverMyG; } } ArrayData choose_Array_Member_Amount(InitialQuestionP Choose){ StartOverMyG : ; clearScreen(); int ArrayMemberTotal; int choice = Choose(); switch(choice){ case INTEGAR: puts("How many members do you need in your Integer Array?"); break; case STRING: puts("How many members do you need in your String Array?"); default: goto StartOverMyG; } scanf("%i", &ArrayMemberTotal); if(choice == INTEGAR){ puts("longlong"); } else if(choice == STRING){ puts("ldl life"); } ArrayData Array_Data; Array_Data.ArrayMemberTotal = ArrayMemberTotal; Array_Data.StringorInt = choice; return Array_Data; } void create_Array(ArrayMemberTotalP Data){ StartOverMyG : ; ArrayData ArrayCreator = Data(Initial_Questions); switch(ArrayCreator.StringorInt){ case INTEGAR: puts("i am Int"); break; case STRING: puts("I am Groot"); break; default: goto StartOverMyG; } } functions.c file
Anonymous
gcc main.c functions.c should compile
14•08
#include <stdio.h> #include "functions.h" #include <stdlib.h> #include <string.h> void clearScreen(void){ printf("\033[H\033[J"); } StringorInt Initial_Questions(void){ StartOverMyG : ; clearScreen(); char stringOrIntegarArrayChoice; puts("Do you want to create a String or an Integer Array?"); puts("Type I for an Integer Array or S for string Array"); scanf("%c", &stringOrIntegarArrayChoice); switch(stringOrIntegarArrayChoice){ case 'I': return INTEGAR; break; case 'S': return STRING; break; default: goto StartOverMyG; } } ArrayData choose_Array_Member_Amount(InitialQuestionP Choose){ StartOverMyG : ; clearScreen(); int ArrayMemberTotal; int choice = Choose(); switch(choice){ case INTEGAR: puts("How many members do you need in your Integer Array?"); break; case STRING: puts("How many members do you need in your String Array?"); default: goto StartOverMyG; } scanf("%i", &ArrayMemberTotal); if(choice == INTEGAR){ puts("longlong"); } else if(choice == STRING){ puts("ldl life"); } ArrayData Array_Data; Array_Data.ArrayMemberTotal = ArrayMemberTotal; Array_Data.StringorInt = choice; return Array_Data; } void create_Array(ArrayMemberTotalP Data){ StartOverMyG : ; ArrayData ArrayCreator = Data(Initial_Questions); switch(ArrayCreator.StringorInt){ case INTEGAR: puts("i am Int"); break; case STRING: puts("I am Groot"); break; default: goto StartOverMyG; } } functions.c file
U repeat the same error