MrNoob 24 Posting Whiz in Training

yes but that should be copy the index which isn't space or tab but see now i changed to use index array members rather than addresses it worked fine i want to know why ?

#include <stdio.h>
#include <ctype.h>
#define STOP -1
int GetLine(char *SzBuff) {
    int i=0;
    char c;
    for( i=0;(c=getchar())!='\n';i++) {
        SzBuff[i]=c;
        if(c==EOF)  {
            SzBuff[i]='\0';
            return -1;
        }
    }
    SzBuff[i]='\0';
    return i;
}
int IsDel(char c) {
    if(c==' ' || c=='\t')   return 1;
    return 0;
}
void RemoveBlanks(char * SzString) {
    int j=0;
    for(int i=0;SzString[i]!=0;i++)
        if(!IsDel(SzString[i]))
            SzString[j++]=SzString[i];
    SzString[j]='\0';
    return;
}
int main(void)
{
    char SzName[100];
    while(GetLine(SzName)!=STOP) {
        RemoveBlanks(SzName);
        if(SzName[0]=='\0')//skip blank lines
            continue;
        puts(SzName);
    }
    return 0;
}
MrNoob 24 Posting Whiz in Training

yah i noticed now but still get bad results same thing

#include <stdio.h>
#include <ctype.h>
#define STOP -1
int GetLine(char *SzBuff) {
    int i=0;
    char c;
    for( i=0;(c=getchar())!='\n';i++) {
        SzBuff[i]=c;
        if(c==EOF)  {
            SzBuff[i]='\0';
            return -1;
        }
    }
    SzBuff[i]='\0';
    return i;
}
int IsDel(char c) {
    if(c==' ' || c=='\t')   return 1;
    return 0;
}
void RemoveBlanks(char * SzString) {
    int j=0;
    while(*SzString) {
        if(!IsDel(*SzString)) { //wtf why the hell does it keep incrementing !!!
            SzString[j++]=*SzString;
            //putchar(SzString[j]);//used for debug
            //getchar();
            //j++;
        }
        SzString++;//this should fucken end the loop why the hell it keep going on incrementing
    }
    SzString[j]='\0';
    return;
}
int main(void)
{
    char SzName[100];
    while(GetLine(SzName)!=STOP) {
        RemoveBlanks(SzName);
        if(SzName[0]=='\0')//skip blank lines
            continue;
        puts(SzName);
    }
    return 0;
}
MrNoob 24 Posting Whiz in Training

you can cr8 a batch file that check attributes of hidden files and then write to batch file after you retrieve them write deleting attribute but thats long task i think there api for these stuff

MrNoob 24 Posting Whiz in Training

here

#include <stdio.h>
void  *memset(void *dest,int val,int cnt)
{
	char *p=(char*)dest;
	while(cnt) {
		*p++=(val+'0');
		cnt--;
	}
	*p='\0';
	return p;
}
int main()
{
	char arr[]={1,2,3,4};
	memset(arr,0,4);
	printf("%s",arr);
	getchar();
	return 0;
}
MrNoob 24 Posting Whiz in Training

with void i think you need to cast according to the type at first not set a void ptr to void ptr

MrNoob 24 Posting Whiz in Training

well bascially here i started with K&R excerises with remove tabes and spaces i m not sure why my programs works in my head it does but even in puesdo code i did it does but arr[j] sometimes get intilised to values before

#include <stdio.h>
#include <ctype.h>
#define STOP -1
int GetLine(char *SzBuff) {
    int i=0;
    char c;
    for( i=0;(c=getchar())!='\n';i++) {
        SzBuff[i]=c;
        if(c==EOF)  return -1;
    }
    SzBuff[i]='\0';
    return i;
}
int IsDel(char c) {
    if(c==' ' || c=='\t')   return 1;
    return 0;
}
void RemoveBlanks(char * SzString) {
    int j=0;
    while(*SzString) {
        if(!IsDel(*SzString)) { //wtf why the hell does it keep incrementing !!!
            SzString[j++]=*SzString;
            //putchar(SzString[j]);//used for debug
            //getchar();
            //j++;
        }
        SzString++;//this should fucken end the loop why the hell it keep going on incrementing
    }
    SzString[j]='\0';
    return;
}
int main(void)
{
    char SzName[100];
    while(GetLine(SzName)!=STOP) {
        RemoveBlanks(SzName);
        if(SzName[0]=='\0')//skip blank lines
            continue;
        puts(SzName);
    }
    return 0;
}

here in RemoveBlanks function
i made this puesdocode for it
while(string not = '\0')
if(not equal to characters specefied)
copyString to String[j] character by character

i don't know whats wrong in it ?

MrNoob 24 Posting Whiz in Training

yes it will work altough u need to work on your indentation

MrNoob 24 Posting Whiz in Training

just make it as an atoi but change base 10 to 16 you can make it unverisal aswell that work for all bases by applying a 2nd argument in atoi copy specifying the base

Dave Sinkula commented: At best I might guess you meant the nonstandard itoa, but I fail to see where that fits into this thread. -6
MrNoob 24 Posting Whiz in Training

lol srsly thats soo stupid thats y most professional programmers arent from college there self taught lol
and btw arrow operator is ptr to structure -> they should tell you basics before you should even tell you to translate program to english

MrNoob 24 Posting Whiz in Training

you should read the documents abt realloc before you do it right away

MrNoob 24 Posting Whiz in Training

you can also do something like
while(!answer())
reget user choice
//then when its out of the loop
puts("welcome to the treasure of centries ");

if you know about functions ofcourse
and if you dont then you could just just do scanf inside loop and keep scanning till while(strcmp(Name1,Name)) you cant compare char * by just relational operators

MrNoob 24 Posting Whiz in Training

also you should note that you forgot to free allocated memory by malloc

MrNoob 24 Posting Whiz in Training

k thanks a lot guys for the information

MrNoob 24 Posting Whiz in Training

oh but why does every bitfield structure has int size can it have a smaller size?

MrNoob 24 Posting Whiz in Training

The unnamed fields may just be padding so that the structure's data is laid out correctly...Gerard4143

it optimize the structure you mean ? or what do you mean by padding ?

MrNoob 24 Posting Whiz in Training

hello i was reading today some stuff abt bitfield but here in this program I understand most of it but there unnamed fields inside the structure book says its stuff for allgiment or something like that
i dont rlly get what does it do

/* fields.c -- define and use fields */

#include <stdio.h>

/* opaque and show */

#define YES     1

#define NO      0

/* line styles     */

#define SOLID   0

#define DOTTED  1

#define DASHED  2

/* primary colors  */

#define BLUE    4

#define GREEN   2

#define RED     1

/* mixed colors    */

#define BLACK   0

#define YELLOW  (RED | GREEN)

#define MAGENTA (RED | BLUE)

#define CYAN    (GREEN | BLUE)

#define WHITE   (RED | GREEN | BLUE)

const char * colors[8] = {"black", "red", "green", "yellow",

            "blue", "magenta", "cyan", "white"};



struct box_props {

    unsigned int opaque         : 1;

    unsigned int fill_color     : 3;

    unsigned int                : 4;

    unsigned int show_border    : 1;

    unsigned int border_color   : 3;

    unsigned int border_style   : 2;

    unsigned int                : 2;

};



void show_settings(const struct box_props * pb);



int main(void)

{

    /* create and initialize box_props structure */

    struct box_props box = {YES, YELLOW , YES, GREEN, DASHED};



    printf("Original box settings:\n");

    show_settings(&box);



    box.opaque = NO;

    box.fill_color = WHITE;

    box.border_color = MAGENTA;

    box.border_style = SOLID;

    printf("\nModified box settings:\n");

    show_settings(&box);



    return 0;

}



void show_settings(const struct box_props * pb)

{

    printf("Box is %s.\n",

            pb->opaque == YES? "opaque": "transparent");

    printf("The fill color is %s.\n", colors[pb->fill_color]);

    printf("Border %s.\n",

            pb->show_border == YES? "shown" : "not …
MrNoob 24 Posting Whiz in Training

oke thanks man a lot for your help

MrNoob 24 Posting Whiz in Training

oh so structure or no structure doesnt matter if its put into an array but why has value changed if i didnt use orignal variable ? since i used only . i thought . only does a copy and when you put it inside other function it will the value will dispear

MrNoob 24 Posting Whiz in Training

and also since i m using a copy since its not ptrs why the value got changed ?

MrNoob 24 Posting Whiz in Training

but why does it work isnt std isnt address since its not like arrays structures names arent addresses?

MrNoob 24 Posting Whiz in Training

its giving me this error

structure.c|40|error: cannot convert `student (*)[4]' to `student**' for argument `1' to `void FillArr(student**, int)'|
structure.c|41|error: cannot convert `student (*)[4]' to `student**' for argument `1' to `void ShowArr(student**, int)'|
||=== Build finished: 2 errors, 0 warnings ===|
but i m passing first address shouldnt the increment operator point to 2nd array of the structure and since i made the structure in the function argument is a ptr to a ptr ?wouldnt that work ?

MrNoob 24 Posting Whiz in Training

hello i m suppose to do this program which should pass array of ptrs to a structure intilise and put student info in each array i did most of it but now i got problem coz i cant just pass address of structure since its an array of ptrs to a structure you cant do &str since that will work on one structure only anyways here is the code

#include <stdio.h>
#define CSIZE 4
typedef struct Names {
    char SzFirst[100];
    char SzLast[100];
}Family;
typedef struct Student {
    Family Handle;
    float Grade[3];
    float Average;
}student;
void EatLines() {
    while(getchar()!='\n')
        continue;
}
void FillArr(student **std,int Size) {
    float sum=0;
    for(int i=0;i<Size;i++) {//Fill info
        printf("Please enter Your first and Last name");
        scanf("%s %s",std[i]->Handle.SzFirst,std[i]->Handle.SzLast);
        EatLines();
        printf("Please enter 3 scores of some of your exams");
        for(int x=0;x<sizeof std[i]->Grade/sizeof std[i]->Grade[0];x++) {
            scanf("%f",&std[i]->Grade[x]);//lol weird code :P
            sum+=std[i]->Grade[x];
        }
        EatLines();
        std[i]->Average= sum / sizeof std[i]->Grade/sizeof std[i]->Grade[0];//average=sum/howmany :P
        sum=0;//reset sum to 0 so we preform some average again on next struct :P
    }
}
void ShowArr(student **std,int Size) {
    for(int i=0;i<Size;i++)
        printf("Student num %d name %s %s and his average score is %d",
                i+1,std[i]->Handle.SzFirst,std[i]->Handle.SzLast,std[i]->Average);
}
int main(void)
{
    student std[CSIZE];
    FillArr(&std,sizeof std/sizeof std[0]);
    ShowArr(&std,sizeof std/sizeof std[0]);
    return 0;
}
MrNoob 24 Posting Whiz in Training

yah solved it but thats weird if they intilise it using
struct employee *em1; they should have did just struct *ptr; then ptr=&em1; lol

MrNoob 24 Posting Whiz in Training

or i have to declare normal structure of same type and make the ptr get its address ?

MrNoob 24 Posting Whiz in Training

i know but isnt this alrdy have the address of the structure ?

MrNoob 24 Posting Whiz in Training

hello i m doing some function for saving a structure of some employee to text but i want to do it using ptrs to struct normally i tried first using ptr to struct in some main function to test some stuff abt it but i get runtime error

#include <stdio.h>
struct employee {
    char SzName[100];
    int age;
    int payee;
};
int main(void)
{
    struct employee *em1;
    em1->age=12;
    printf("%d\n",em1->age);
    getchar();
    return 0;
}

why do i get this runtime error ? its like doign *x=12 but with structures or do i get runtime error coz the ptr to struct isnt intilised ?but its alrdy intilised since struct employee *em1 should point to its aaddress or whats wrong ?

MrNoob 24 Posting Whiz in Training

you can also use strncmp or use strchr to remove new line after each time fgets reads the string

MrNoob 24 Posting Whiz in Training

i think something like this would work

for(int n=0;n<=sizeof SzStrings/SzStrings[0];n++)
     {
       Putrand(append_test_data);
       if(strcmp(append_test_data, SzStrings[n]) == 0)
                {
                   printf("Append data is =%s\n",append_test_data);
                   printf("constraint is found=%s\n", SzStrings[n]);

                   getch();
                  return 0;

              }
     }
MrNoob 24 Posting Whiz in Training

its "a1,b1,c1".
i use const_array as double array so that everytime i just query the row,not the column.
and append_test _data is just a string array.
do u meant with this declaration :
char append_test_data [MAX_LENGTH]="";
i use "" in this array.does it effect?

normally append_test_data[MAX_LENGTH]="";
is just \0 stored in it do you want to make user each time get string from him through the loop and then compare it ? also note that int n=1 that will start from 2nd array count not first since arrays start from 0 could you also post full code to see whats wrong with it

MrNoob 24 Posting Whiz in Training

also arrays starts at 0 count not 1

MrNoob 24 Posting Whiz in Training

if its multi dimensional array then u have to keep track of the counts ur comparing like for example
for(i=0;i<MAX;i++) //this is a case in which string have same count
if(!strcmp(SzString,SzString2)) { //do stuff};

MrNoob 24 Posting Whiz in Training

just post your code and show whats wrong with it and what do you mean by return 35 times ? you mean there will be 35 seats in the bus ? and max booking is not more than 35 seats?

MrNoob 24 Posting Whiz in Training

yes but problem if i change hex to characters it will be mixed like 676867 and like that and id have to change it back to strings i m sorry for not answering fast internet was off

MrNoob 24 Posting Whiz in Training

hello guys i m wondering how to convert hex to string

kvprajapati commented: I am too. Don't spam. -2
MrNoob 24 Posting Whiz in Training

or maybe read hole the txt into a string and then use strstr something like this

MrNoob 24 Posting Whiz in Training

just use strstr and use its return value to copy it

yellowSnow commented: Stop posting for the sake of posting .. it's annoying! -1
MrNoob 24 Posting Whiz in Training

I got one idea though coz hang man doesnt require junk genrator names unless you do a real name genrator my idea is have the program read from you 3 names for the movies or any other names and it will choose randomly between the 3 or more if you want to then after ur done with them u can rewrite them or having program calloc for more if you need more than 3 names

MrNoob 24 Posting Whiz in Training

thanks guys

MrNoob 24 Posting Whiz in Training

why dont u use fgetc and put str[c]=c; ?

MrNoob 24 Posting Whiz in Training

and you can also use while(*p++) it will increment addr till it meet \0 in a char *

MrNoob 24 Posting Whiz in Training

oh so when loop see \n getchar() reads it and discards then quit the loop ? what i mean by quit is it will start another looping from beging so it discards the newline encountered by scanf right ?

MrNoob 24 Posting Whiz in Training

Hello guys I am reading some book but there and went to input validation but there is something logical i dont get in it you know when press enter with getchar() sometimes it transmits newline to the program but book has solution but i don't know why it works i m confused about it

while (getchar() != 'y')   /* get response, compare to y */

{

    printf("Well, then, is it %d?\n", ++guess);

    while (getchar() != '\n')

        continue;          /* skip rest of input line    */

}

but this will discard rest of the line but the \n it wont discard it since the loop will quit when it reads \n ? shouldnt it be while(getchar()=='\n')
continue;
now it will discard it ?
wouldnt it be better to do this

while( we getting char not = eof) {
 if(char == '\n') 
          continue;//wouldnt it be better to use this ?
}

i know first one will discard every character but why does it discard the \n also ?

MrNoob 24 Posting Whiz in Training

i think i had some bugg but now its still in whilever loop dam this gonna drive me insane

#include <stdio.h>
#include <ctype.h>
#include <string.h>
void ParseSpaces(char *str,char *str2,int *space1,int *space2,int *str1count,int *str2count) {
    int i,x;
    *space1=*space2=0;//set both to 0 so we dont be incrementing addresses
    *str1count=*str2count=0;//set both to 0 so we dont be incrementing addresses
    while( *str!=0 ) {
        ++(*str1count);
        if(*str==' ')
            ++(*space1);
        str++;
    }
    while(*str2!=0) {
        ++(*str2count);
        if(*str2==' ')
            ++(*space2);
        str2++;
    }
}

void FixStr(char *str1,char *str2,char *biggest,char *smallest) {//stands for parse biggest string
    int num;
    if(strlen(str1) > strlen(str2) ) {
        for(num=0;str1[num]!=0;num++)
            biggest[num]=str1[num];//keep setting temp[num] to str1[num
        biggest[num]='\0';//set to NULL character

        //now we gonna set the smallest buffer
        for(num=0;str2[num]!=0;num++)
            smallest[num]=str2[num];
        smallest[num]='\0';//set to NULL character
    }
    else {
        for(num=0;str2[num]!=0;num++)
            biggest[num]=str2[num];
        biggest[num]='\0';

         for(num=0;str1[num]!=0;num++)
            smallest[num]=str1[num];
        smallest[num]='\0';//set to NULL character
    }
}
char * String_Within(char *str1,char *str2) {
    int Sspaces1,Sspace2,str1count,str2count;
    int num;//to find the biggest count and run loop acccording to it
    int Tracker=0;//to keep track of the String
    char Biggest[50];//holds biggest array
    char Smallest[50];//holds smallest array
    char tempp[50];//which will get the strings that are ==
    int chars1=0;//will keep track of chars if there == then we will do some for loop stuff in the while
    int chars2=0;//will keep track of chars if there == then we will do some for loop stuff in the while
    int Tr=0,Tr2=0;//keep track of certain variables
    int x=0;//which we will use to make loop run till we fix str
    int counter=0;//certain variable in our for loop
    int temporlily=0;//to increment this variable so if same as …
MrNoob 24 Posting Whiz in Training

okay i think how i will do it i desinged the function etc but now the problem is its getting in for loop first i knew how to change first the strings that are = and after that when i copy strings that are = to a temporily array then after that i will compare both to largest str and smallest str with the temporirly and get the strings that arent =

now problem is that my function get in a forever loop even though i made test inside once stuff are done it will set x to 10 which will break out of the loop !!!! this stupid function driving me insane

#include <stdio.h>
#include <ctype.h>
#include <string.h>
void ParseSpaces(char *str,char *str2,int *space1,int *space2,int *str1count,int *str2count) {
    int i,x;
    *space1=*space2=0;//set both to 0 so we dont be incrementing addresses
    *str1count=*str2count=0;//set both to 0 so we dont be incrementing addresses
    while( *str!=0 ) {
        ++(*str1count);
        if(*str==' ')
            ++(*space1);
        str++;
    }
    while(*str2!=0) {
        ++(*str2count);
        if(*str2==' ')
            ++(*space2);
        str2++;
    }
}

void FixStr(char *str1,char *str2,char *biggest,char *smallest) {//stands for parse biggest string
    int num;
    if(strlen(str1) > strlen(str2) ) {
        for(num=0;str1[num]!=0;num++)
            biggest[num]=str1[num];//keep setting temp[num] to str1[num
        biggest[num]='\0';//set to NULL character

        //now we gonna set the smallest buffer
        for(num=0;str2[num]!=0;num++)
            smallest[num]=str2[num];
        smallest[num]='\0';//set to NULL character
    }
    else {
        for(num=0;str2[num]!=0;num++)
            biggest[num]=str2[num];
        biggest[num]='\0';

         for(num=0;str1[num]!=0;num++)
            smallest[num]=str1[num];
        smallest[num]='\0';//set to NULL character
    }
}
char * String_Within(char *str1,char *str2) {
    int Sspaces1,Sspace2,str1count,str2count;
    int num;//to find the biggest count and run loop acccording to it
    int Tracker=0;//to keep track …
MrNoob 24 Posting Whiz in Training

yah comparing word by word i got one idea but i dunno how to do first i will count all spaces in both if there is 1 it will only do strcmp between both if there 2 or 3 it will first somehow like first word if its count greater than 1st word in 2nd string it will ignore that and put that inside temp which we will return l8er if its the same it should compare them but the temp wont be in the thing so if it doesnt find the chars not = it wont put that in temp .......

MrNoob 24 Posting Whiz in Training

first string will change to is man
and return this cool ool

MrNoob 24 Posting Whiz in Training

well i did mention expected output the problem in my program here that one string after the space can be larger than the other so if we got a 3rd string even if they match it will say it wont match because he will be i+1 comparing to x so it wont match if somehow i could just strlen the char after space if there the same then i should apply an if test ...

MrNoob 24 Posting Whiz in Training

yah but i dont wanna use any standard function i wanna do it myself

MrNoob 24 Posting Whiz in Training

well it should extract the strings to are equal to first char * and return the string that are diffrence like for example this is cool this is bad it will return cool bad and change first string to this is

MrNoob 24 Posting Whiz in Training

hmm i had a lot of problems in that code i changed that but now problem is left that sometimes the 1st chars has more char than other so it wont test it even if the 3rd string are == there will be one char that surpasses the other this is i think there must be easier way to do this than the way i m doing ....

#include <stdio.h>
#include <ctype.h>
char * String_Within(char *str1,char *str2) {

    char temp[50];
    int i,x=0;
    int z=0;
    int num=0;
    int buff=1;
    /*first of all lets run in a double for loop and each time will be less than the certain num */
    /*that certain num will have to know when the space is there and 2nd time is run we += it so it doesnt stop at that space again */
    //first of all lets read in nested loop
    for( i=num ;  str1[i]!=0 ; i++ ) {
        for( x=num ; x<buff; x++ ) {
            printf("\nhere str[i] %c and here str[x] %c\n",str1[i],str2[x]);
            getchar();
            if(str2[x]==str1[i]) {
                temp[z]=str1[i];
                z++;
            }
            if(isspace(str2[x]) && isspace(str1[i])) {
                num++;
                break;
            }
            else if(str1[i]!=str2[x]) {
                num++;
                printf("\nsorry characters here are they %c %c\n",str1[i],str2[x]);
                break;
            }
            //we will keep incrementing num
            num++;
        }
        buff+=1;
        temp[z]=' ';//add a space to the character we have atm
    }
    temp[z]='\0';//to put null character
    puts("now we are printing temp\n");
    puts(temp);
    //we gonna return it later now
}
int main(void)
{
    char Name[]="thats a good dog";
    char Name1[]="thats a good coder";
    char *ptr;
    ptr=String_Within(Name,Name1);
    //will figure out …