MrNoob 24 Posting Whiz in Training

hi,
I have some problems with winsock library so I am calling loading it dynmically then calling the functions so far so good,but the problem is for example I see in the winsock2 header files that -
GetHostByName and some other functions are which I use there prototypes is kinda weird for example GetHostByName prototype is
DECLARE_STDCALL_P(struct hostent *) gethostbyname(const char*);

I know gethostbyname returns a struct hostent * but I don't see its calling convetion neither __stdcall or pascal or fastcall so I can convert it into typedef pointer then use it to dynmically call the function.

thanks.

MrNoob.

MrNoob 24 Posting Whiz in Training

then why don't you find 22 then after that -1 if the number before it is 22 then decrement it again untill the number is not 22 then you have there is your first 22

Ancient Dragon commented: Good solution. +26
MrNoob 24 Posting Whiz in Training

if you want to manipulate bmp files you have to read it's structure

MrNoob 24 Posting Whiz in Training

anyways thanks i get where did i go wrong stupid me :D since i m allocating my inner array as rows i should have went i < rows not i < cols
thanks it works now.

MrNoob 24 Posting Whiz in Training

yes it's .cpp

MrNoob 24 Posting Whiz in Training

oke I was coding some stuff involving 2d array allocating i normally know how to do it in main coz you don't need to pass adr main ptr that get's allocated but when i made it i got somewhat confused I don't know why it went wrong

#include <stdio.h>
#include <windows.h>
BOOL AllocateMemory(int ***iArray,int rows,int cols) {
     *iArray = (int**)calloc(rows,sizeof(int));
     if(!*iArray)
         return false;
     for(int i =0;i < cols;i++) {
         **iArray = (int*)calloc(cols,sizeof(int));
         if(!**iArray)
             return false;
     }
     return true;
}
void FreeAllocated(int **iArray,int rows,int cols) {
     for(int i = 0; i < rows;i++) {
         for(int x = 0;x < cols;x++)
              free(*iArray);
         free(iArray);
     }
     return;
}
              
void ShowArr(int **iArray,int rows,int cols) {
     for(int i = 0; i < rows;i++)
     for(int x = 0 ; x < cols ;x++)
         printf("%d\n",iArray[i][x]);
}

int main(void)
{
    int **iArray;
    if(AllocateMemory(&iArray,3,3)) {
       ShowArr(iArray,3,3);
       FreeAllocated(iArray,3,3);
    }
    getchar();
    return 0;
}

ShowArr should show all 0 but it shows first i made allocating ptr to ptr then after that in loop i made allocate ptr to int only which should be right ..

MrNoob 24 Posting Whiz in Training

oke thanks again mate for answering my questions

MrNoob 24 Posting Whiz in Training

oke but there something that bugging 2 questions acctually
does it chooses the multipales randomly ? of the file or in memory for example file alignments is 0x200 does it chooses it's stuff randomly ? or based on some facts ? also for pe files in memory version is aligned to 0x100 wouldn't that make program bigger in memory than in file ?

MrNoob 24 Posting Whiz in Training

hey i got something again i got confused by in PE files and they don't rlly explain why happens oke so what im confused with FileAlignment and SectionAlignment

files must be aligned or sections to whatever count is right ? like if the it's less than the number (x) then it will aligned to certain number so and stuff there is filled with zeros ?

MrNoob 24 Posting Whiz in Training

I got problem with this function for adding icon to a program with small programs it corupts it and with bigger programs it doesn't even do anything

#include <stdio.h>
#include <windows.h>
#define MIN 2
char *ReadFile(char *SzFile,int *BytesCount) {
    int fSize;
    FILE *pFile;
    char *Buffer;
    if(!(pFile=fopen(SzFile,"rb")))
        return NULL;
    fseek(pFile,0,SEEK_END);
    fSize=ftell(pFile);
    rewind(pFile);
    if(!(Buffer=(char*)calloc(fSize,sizeof(char))))
        return NULL;
    fread(Buffer,fSize,1,pFile);
    *BytesCount=fSize;
    return Buffer;
}
bool AddIcon(char *SzFile,char *SzIcon) {
    HANDLE ih;
    char *Buffer;
    int fSize=0;
    if(!(Buffer=ReadFile(SzIcon,&fSize)) || !(ih=BeginUpdateResource(SzFile,FALSE)) \
       || !UpdateResource(ih,MAKEINTRESOURCE(3),MAKEINTRESOURCE(50),0,Buffer+22,fSize-22) \
       || !EndUpdateResource(ih,FALSE)
      ){
            Buffer ? free(Buffer) , ih ? CloseHandle(ih) : 0 : 0;
            return false;
       }
    free(Buffer),CloseHandle(ih);
    return true;
}
int main(int argc,char *argv[])
{
    if(argc<MIN) {
        printf("wrong usage: must be bigger than %d\n",MIN);
        return 1;
    }
    int sucess=0;
    for(int i=1;i<argc;i++)
        if(AddIcon(argv[i],argv[argc-1])) {
            printf("\nadded icon %s to file %s\n",argv[argc-1],argv[i]);
            sucess++;
        }
    printf("we succesfully added %d icons",sucess);
    return 0;
}

I searched all the net i couldn't find what's the problem this is
hopefully someone will help me what's wrong

MrNoob 24 Posting Whiz in Training

you can just use strstr but if you want to do it with pop only you can start at end of the stack then keep popping till a space is reached when a space is reached u end that word and compare it with the specified word you want

MrNoob 24 Posting Whiz in Training

why don't u just use fgets and read in portion coz like this your scanning starting addr of the file which u can't do that coz u didn't read the buffer of the file or anything into a string so u cant expect it to start directly i suggest you use fgets since u want to compare some string you can read the all buffer at once using fread

MrNoob 24 Posting Whiz in Training

that is if the name itself is ended with null terminator

MrNoob 24 Posting Whiz in Training

start with strlen(name)-1 then pop untill limit is reached or when char itself ur popping got space in it

MrNoob 24 Posting Whiz in Training

remeber in binary search it stuff needs to be arranged i didn't read your code but i don't see any arranging function in it

MrNoob 24 Posting Whiz in Training

oke thanks a lot for the information was useful

MrNoob 24 Posting Whiz in Training

oh thanks but when you load executable does it load directly in RAM or it gets loaded in hdd and sent to pages to hdd or it's vice versa ?

MrNoob 24 Posting Whiz in Training

well maybe u can define ; as a other name then use other name as derived type

MrNoob 24 Posting Whiz in Training

also remeber don't use void main since u might want to check it's return value if it's return sucess or right also main is a specailized function which alawys start the program at like entry point for example . u should see some tutorials on c before doing anything on it.

MrNoob 24 Posting Whiz in Training

you can use code blocks it's cool

MrNoob 24 Posting Whiz in Training

hey i was reading some stuff about windows i was wondering if file is loaded at virtual memory and let's say we load many files at once wouldn't that cause thrashing ? or exucatables are loaded into RAM then copied to virtual memory of hdd ?

MrNoob 24 Posting Whiz in Training

also why do u intilise first time just use the push function
when u want to intilise and when u want to delete u should pop it

MrNoob 24 Posting Whiz in Training

you forgot to use the return value of your structure just place p=func(p);
or if u want to use p to initialize and then use it's value u can use ptr to a structure

MrNoob 24 Posting Whiz in Training

c doesn't have call by refrence since the value if it's not a ptr it won't change only it's copy will in the function if u want it to change u need to pass the address

MrNoob 24 Posting Whiz in Training

oh alright thanks for info

MrNoob 24 Posting Whiz in Training

but aren't RVA is on load time ? so code will be build but will crash ? or it's alrdy there when exe compiles ?

MrNoob 24 Posting Whiz in Training

it's used in the static memory that memory is intilised and won't quit like automatic variables it will retain there values even after functions end

MrNoob 24 Posting Whiz in Training

hey i m reading about pe format but there something that i don't get RVA in documentation it says it just like a temp for addressing memory in other sections ok and it's just a DWORD what if there are many temperoralily variables wouldnt that overflow the that RVA value or i got the concenpt of RVA values all wrong ???

MrNoob 24 Posting Whiz in Training

oh i see so stand library every os has its own set and also each compiler for that os produce the file format etc .

MrNoob 24 Posting Whiz in Training

hi i m sorry for this noob question but there something i don't get i was reading abt File format like PE for example i was wondering how is C unverisal on MAC win and unix since they use diffrent file format does C takes care of each file format while compiling like it has pre defined file format in it or that's compiler specific ?

MrNoob 24 Posting Whiz in Training

i fixed it problem was in the increment line 68 coz i used to postfix increment it and also there was a bug

#include <stdio.h>
#include <stdlib.h> /* for atof() */
#include <ctype.h>
#include <math.h>
#include <string.h>
#define ClearStack(n) n=0 //which makes just the external variable count var point to first member then the elements will get overwritten
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
#define MAXVAL 100 /* maximum depth of val stack */
#define BUFSIZE 100
int sp = 0; /* next free stack position */
int val[MAXVAL]; /* value stack */
int getop(char []);
void push(int);
int pop(void);
/* reverse Polish calculator */
int getline(char *s) {
    int c;
    //we first get line then stop at first new line encounter or at first operand then we reparse the shit
    for(int count=0;(c=getchar())!=EOF;count++) {
         s[count]=c;
        if(c=='\n') {
            s[count]='\0';//we forgot to end the string so thats y shit happened
            return true;
        }
    }
    //it means loop ended by EOF which means we need to return false
    return false; //means EOF is reached mate :D we should now quit the loop
}
void push(int f) {
    if (sp < MAXVAL)
        val[sp++] = f;
    else
        printf("error: stack full, can't push %g\n", f);
}
int pop(void) {
    int temp=sp;
    if (sp > 0) {
        //printf("pop() function val[--sp] line 39 %d and pop again is %d\n",val[--temp],val[temp-2]);
        //getchar();
        return val[--sp];
    }
    else {
        printf("error: stack empty\n");
        return 0;
    } …
MrNoob 24 Posting Whiz in Training

yes i will add that but i don't want to rewrite the hole thing so i may never know what went wrong here so i won't rlly improve so that's y i want to know what i m doing wrong here so i will be able to avoid that next time i m coding something new also i m having a bit hardtime with the forum it's lagging bad

MrNoob 24 Posting Whiz in Training

anyways thanks for clarifying the function for me

MrNoob 24 Posting Whiz in Training

i fixed problem was that i incremented sp then used it in printf which made it next time i used the value i used the incremented one which contained rubbish value

MrNoob 24 Posting Whiz in Training

thats y i implemented it according

MrNoob 24 Posting Whiz in Training

yes but polish notation of K&R is 2 4 + not 2 + 4

MrNoob 24 Posting Whiz in Training

hey i m here supposed to extend calculator of K&R to support getline i made it but i dunno everytime i keep getting 0 poped not the numbers itself i debuged it i couldn't find where the bug is so hopefully someone will tell me what i m doing wrong here

#include <stdio.h>
#include <stdlib.h> /* for atof() */
#include <ctype.h>
#include <math.h>
#include <string.h>
#define ClearStack(n) n=0 //which makes just the external variable count var point to first member then the elements will get overwritten
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
#define MAXVAL 100 /* maximum depth of val stack */
#define BUFSIZE 100
int sp = 0; /* next free stack position */
double val[MAXVAL]; /* value stack */
int getop(char []);
void push(double);
double pop(void);
/* reverse Polish calculator */
int getline(char *s) {
    int c;
    //we first get line then stop at first new line encounter or at first operand then we reparse the shit
    for(int count=0;(c=getchar())!=EOF;count++) {
         s[count]=c;
        if(c=='\n') {
            s[count]='\0';//we forgot to end the string so thats y shit happened
            return true;
        }
    }
    //it means loop ended by EOF which means we need to return false
    return false; //means EOF is reached mate :D we should now quit the loop
}
void push(double f) {
    if (sp < MAXVAL)
        val[sp++] = f;
    else
        printf("error: stack full, can't push %g\n", f);
}
double pop(void) {
    if (sp …
MrNoob 24 Posting Whiz in Training

well you could do this in puesdo code

#define test 5
for(n=0;n is less than or = to 9;increment n)
     if(n is less than test)
        for(int x=0;x is less then n;increment x) /*used for till max is found*/
             print(star)
    else its bigger than test //then we must do in reverse order 
          for(int x=n; x is less than or = to 9;increment x)
                  print(star);
     putnewline;
}
MrNoob 24 Posting Whiz in Training

here your simply doing a loop that prints 5 character untill row becomes 9
and that code

if (row)
{
     printf (" ");
     row++;
}

else
{
     printf(" ");
     row--;
}

will never enter row-- since any non zero number is true what u should do is explain in insruction to yourself how to do this

MrNoob 24 Posting Whiz in Training

"" stuff between is character string '' between s character which has ascii representions or can be any other system represention like strings always end with NULL to mark the end character is just 1 character

MrNoob 24 Posting Whiz in Training

well i don't really have much knowledge in language development but if you want it like middle language you can use asm after all c is asm based

MrNoob 24 Posting Whiz in Training

okay i understood it but i got other problem now its not acctually a problem but the exerise to add - i got it to work aswell but when i added couple of printf it didn't work this is weird

#include <stdio.h>
#include <stdlib.h> /* for atof() */
#include <ctype.h>
#include <math.h>
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
#define MAXVAL 100 /* maximum depth of val stack */
#define BUFSIZE 100
int sp = 0; /* next free stack position */
double val[MAXVAL]; /* value stack */
int getop(char []);
void push(double);
double pop(void);
/* reverse Polish calculator */
int main(void)
{
    int type;
    int i=0,count=0;
    double op2;
    char s[MAXOP];
    while ((type = getop(s)) != EOF) {
        switch (type) {
            case NUMBER:
                push(atof(s));
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push( pop() * pop() );
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(fmod(pop(),op2));
                else
                    printf("error: zero divisor\n");
                    break;
            case '%':
                op2 = pop();
                    if(op2!=0)
                        fmod(pop(), op2);
            case '\n':
                printf("\tanswer is%.8g\n", pop());
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;
        }
    }
    return 0;
}
/* push: push f onto value stack */
void push(double f)
{

    if (sp < MAXVAL) {
        val[sp++] = f;
        printf("val[sp]=%g",val[sp]);//we gonna use for verifacation
        getchar();
    }
    else
        printf("error: stack full, can't push %g\n", f);
}
/* pop: pop and return top value from stack …
MrNoob 24 Posting Whiz in Training

no after while basically while means repeat code 3 times if he doesnt those 3 times do something then after 3 tries a error should be displayed

MrNoob 24 Posting Whiz in Training

okay thanks i get it but there isn't the order of evulatution for
while (isdigit(s[++i] = c = getch())) ; is right to left ?
like for example after we enter at test if(c=='.') shouldnt it quit coz
isdigit(s[++i] contains nothing or coz i m doing it inside the function i m assigning that ++i to the character that will get read ?

MrNoob 24 Posting Whiz in Training

nvm about buff deceremting part it won't decerement it only after 2nd time i think but how does ungetch deletes input ?

MrNoob 24 Posting Whiz in Training

why dont you use realloc rather than freeing and allocating?

NicAx64 commented: realloc good point +1
MrNoob 24 Posting Whiz in Training

Hello here in k&r excerise of primitive calculator i get it and all but there something i think its weird and i don't somewhat get it here the getch and ungetch functions i don't get it's routine

#include <stdio.h>
#include <stdlib.h> /* for atof() */
#include <ctype.h>
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
#define MAXVAL 100 /* maximum depth of val stack */
#define BUFSIZE 100
int sp = 0; /* next free stack position */
double val[MAXVAL]; /* value stack */
int getop(char []);
void push(double);
double pop(void);
/* reverse Polish calculator */
int main(void)
{
    int type;
    double op2;
    char s[MAXOP];
    while ((type = getop(s)) != EOF) {
        switch (type) {
            case NUMBER:
                push(atof(s));
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push(pop() * pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else
                    printf("error: zero divisor\n");
                    break;
            case '\n':
                printf("\t%.8g\n", pop());
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;
        }
    }
    return 0;
}
/* push: push f onto value stack */
void push(double f)
{
    if (sp < MAXVAL)
        val[sp++] = f;

    else
        printf("error: stack full, can't push %g\n", f);
}
/* pop: pop and return top value from stack */
double pop(void) {
    
    if (sp > 0)
        return val[--sp];
    else {
        printf("error: stack empty\n");
        return 0.0;
    }
}

int getch(void);
void ungetch(int);
/* …
MrNoob 24 Posting Whiz in Training

just do nested loop first loop looping through file and 2nd loop checking if that string is contained within if its contained then use strstr and delete that by placing NULL at its ptr then rewrite it to other file

jephthah commented: write NULLs in the middle of a file to delete a line? Seriously?? -1
MrNoob 24 Posting Whiz in Training

also why don't you use
and operator if(!strcmp(pw,pw)) && if(!strcmp(idid)) { excute following command}; also you should convert a to either upper or lower so you do better only 1 if statement

MrNoob 24 Posting Whiz in Training

oh thanks man i thought addresses is same as indexes but i guess i was wrong