Anonymous
but that function also takes another function as an argument
olli
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
14•08
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...
olli
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??
olli
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?
Anonymous
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
Anonymous
Do I have to post the code
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'
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
olli
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
depends, if the function pointers are part of an API you can put them in the same header as your function declarations.
Anonymous
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
14•08
Anonymous
14•08
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
gcc main.c functions.c should compile
14•08