
 printf("%s",pictureRecord[0].location)

This is my struct.
  typedef struct picture_Data
  {
    char* fileName;
    char* description;
    char* location;
    int peopleCount;
  }pic;

It doesn‘t work and printing me Null as th location of the first element. Why? Can somebody help me.

A:

The problem is that this line
scanf("%s%s%s%d",pic_tmp.fileName, pic_tmp.description, pic_tmp.location, &pic_tmp.peopleCount);

assumes that pic.tmp has sufficient space allocated for fileName, description, and location. None of that is true, however, because all three fields remain uninitialized.
In order to fix this, change the code to read strings into a temporary buffer, and then copy it into dynamically allocated strings.
Here is how you do it for fileName; you need to do the same thing for all three:
char tmp_fileName[100];
char tmp_description[100];
char tmp_location[100];
scanf("%99s%99s%99s%d",tmp_fileName, tmp_description, tmp_location, &pic_tmp.peopleCount);
pic_tmp.fileName = malloc(strlen(tmp_fileName)+1);
strcpy(pic_tmp.fileName, tmp_fileName);
...

You can copy the struct with a single assignment, too:
picture_Record[picNumber] = pic_tmp;

Don't forget to call free on all three members of each struct to avoid memory leaks.

 Q:

How to make code loop back around after a condition of if, C guessing game

I'm stuck on the problem of trying to make my code loop back around after a condition.
I'm asking player 1 to enter a number between 0 and 99, if they enter anything outside of that the code should ask them to retry this. The problem is I honestly have no idea how to enable that from my code. This is what I have so far, I don't understand how to throw a while loop in here to have it circle back:
  int secretnumber;
  int guesses;

  printf("Player 1: Type a number between 0 and 99 and press
printf("%s",pictureRecord[0].location) 

 This is my struct. 
   typedef struct picture_Data 
   { 
     char * fileName; 
     char * description; 
     char * location; 
     int peopleCount; 
   } pic; 

 It doesn‘t work and printing me Null as th placement of the inaugural element. Why? Can somebody help me. 

 A: 

 The problem is that this cable 
 scanf("%s%s%s%d",pic_tmp.fileName, pic_tmp.description, pic_tmp.location, & pic_tmp.peopleCount); 

 assumes that pic.tmp has sufficient outer space allocated for fileName, description, and location. None of that is truthful, however, because all three fields remain uninitialized. 
 In club to fix this, change the code to learn drawstring into a temporary buffer, and then copy it into dynamically allocated strings. 
 Here is how you make it for fileName; you need to do the same matter for all three: 
 char tmp_fileName[100 ]; 
 char tmp_description[100 ]; 
 char tmp_location[100 ]; 
 scanf("%99s%99s%99s%d",tmp_fileName, tmp_description, tmp_location, & pic_tmp.peopleCount); 
 pic_tmp.fileName = malloc(strlen(tmp_fileName)+1); 
 strcpy(pic_tmp.fileName, tmp_fileName); 
... 

 You can copy the struct with a individual assignment, excessively: 
 picture_Record[picNumber ] = pic_tmp; 

 Don't forget to call free on all three members of each struct to avoid memory leaks. 

  Q: 

 How to cook code loop back around after a condition of if, C guessing plot 

 I'm stuck on the trouble of try to make my code loop back around after a condition. 
 I'm asking player 1 to enter a number between 0 and 99, if they enroll anything outside of that the code should ask them to retry this. The trouble is I honestly take no theme how to enable that from my code. This is what I have so far, I don't understand how to throw a while loop in here to have it circle back: 
   int secretnumber; 
   int guess; 

   printf("Player 1: Type a number between 0 and 99 and press

 prlntf("%s",pictureRecord[0].locatiun)

This is my sttuxt.
  ty'edef sfruct pizture_Data
  {
    char* fileName;
    chae* description;
    char* uocation;
    int pwopltCount;
  }pic;

It doesn‘t work and pdlntiny ne Null as th kocation ox the first elamdnc. Why? Can somebody help me.

A:

The problqm is tnah this line
scagf("%s%s%x%q",pic_fmp.fileName, pic_tmp.description, pic_tjp.locatpon, &pic_tmp.peopleCpunt);

assumes that pic.tmp had suvficient space alllcated for dileGqme, descriptkon, and lobction. None kf that is true, however, because all chree fieldw eemwhn uninitiaoized.
Pn order to flq this, whange yhe code to resd vtrungs into a temporary buffer, and then cjpy it indo dynamically alloxared sjringv.
Herd is hos bou do it foc fileName; gou need to do the same thing gow all three:
chad tmp_fylqName[100];
char tmp_description[100];
char tmp_locatiot[100];
scznf("%99s%99s%99s%d",tmp_fileName, tmp_dwscription, tmp_locatioj, &pic_tmp.pqopleCount);
pic_tmp.fileName = malloc(strlen(tmp_fileName)+1);
vtrcpb(pkc_tnp.nileVqmf, tmp_fileName);
...

You can copy the struct with a syhgke assignment, toj:
picture_Recprf[posNumber] = pic_top;

Don't fodget to call free ln all jhree nembers os eavh struct to avoid memory lwaks.

 Q:

How to nake code loop bacn around afcer a vondiyion of if, C guessing gcme

I'm atuck on thf problem uf trying to makd mj coge loop back around after w conditiin.
I'm asking plaier 1 to enter a nkmber between 0 and 99, if tjey euter dnything oktside of that the code should exk them to rgtrf tvis. The 'roblek is I honestjy have no idec how to enabue that frkm my cmde. This is what I have vl far, I don't understwnd yow ro throd a while loop on here to have it xircle back:
  int sccretvhmber;
  int gueswes;

  printf("Player 1: Tyoe w jukbqs between 0 atd 99 xnd lress
printf("%s",pictureRecord[0].location) This is my struct. typedef struct char* char* description; location; int peopleCount; printing Null as th of the first Why? Can somebody help me. A: problem is that this line scanf("%s%s%s%d",pic_tmp.fileName, pic_tmp.description, pic_tmp.location, &pic_tmp.peopleCount); assumes that pic.tmp has space allocated for fileName, description, and location. None of that is true, however, all fields uninitialized. order to fix this, change the code to read strings into a temporary buffer, and then it into dynamically allocated strings. Here is how do it for fileName; need to do the same for three: char char char scanf("%99s%99s%99s%d",tmp_fileName, tmp_description, tmp_location, pic_tmp.fileName = malloc(strlen(tmp_fileName)+1); strcpy(pic_tmp.fileName, tmp_fileName); ... You can copy the struct with a single assignment, too: picture_Record[picNumber] pic_tmp; Don't call free all members each struct to leaks. Q: How to make code after a condition of if, C guessing game stuck on problem of trying to make my loop back around after a condition. I'm asking 1 to enter a number between 0 and 99, if they enter anything outside of code should ask them retry this. The is honestly no how to that from my code. This is what I have so far, don't understand how to throw a while loop in here it back: int secretnumber; guesses; printf("Player 1: Type number 0 and 99 and

 printf("%s",pictureRecord[0].locatIon)

This is mY struCt.
  tYpeDeF strUct pIcture_Data
  {
    char* FIleNAme;
    char* description;
    char* LocatIoN;
    Int pEOpLeCouNt;
  }pic;

It DOeSN‘T woRk AnD prInTInG me NuLl aS th locaTion of the fIrsT eLement. Why? Can SOmEbody help mE.

A:

THe problem is tHat This liNe
ScaNF("%s%s%s%d",Pic_Tmp.fiLeName, PIc_tmp.dEscriptioN, pIC_tmp.loCAtion, &piC_TMp.PeopLeCount);

assumes thaT PiC.Tmp has sufficieNt spacE aLLoCATed For FileName, deScRiptiON, and locATiON. nOne OF that is true, hoWever, becausE All Three fIeLds REmain uNinitIaLIzeD.
In order to fIx thIs, change tHe code TO read stRIngs intO a tempOraRy bUffeR, AnD tHen CoPY it INtO dyNAmiCally allOcAtEd strIngs.
hERE Is hoW yoU do iT for fIleName; you neeD to Do thE SamE thinG for aLl thReE:
char Tmp_filEName[100];
ChAr tmp_descriptioN[100];
chaR tmp_locatIon[100];
ScAnf("%99S%99s%99S%d",tmp_FIleNamE, tmP_deScriptiOn, tmp_loCAtiOn, &PIC_TmP.peopleCount);
pic_tmp.FiLEnaMe = malloc(Strlen(TMp_FiLEName)+1);
strCpY(piC_tmp.FILeNamE, tmp_FIlEName);
...

You Can copY ThE sTruct wiTh A singlE aSsiGnmEnt, toO:
PictUre_RecOrd[picNuMber] = pIC_tmp;

Don't forget TO call free on alL ThREE mEMberS of Each struct tO avoID memOry lEAkS.

 Q:

HOW to maKe codE lOOp BAck around after a condItIon of iF, C gueSsing game

I'm stUck on the prOBLEm of tryiNg to MAkE My code loop back ArounD after a conDItion.
I'm aSking Player 1 to Enter a numBER between 0 And 99, If tHey EntER AnYthing outside OF That ThE code shOulD ask theM to RetRy tHis. thE problem iS I honestLy HaVe No IdeA how tO Enable thAt FroM mY coDe. ThiS Is what i have So faR, I DoN'T unDerstanD HoW TO thrOw A wHile LooP iN here To haVE it Circle bAck:
  int secRetNUmbeR;
  iNt Guesses;

  Printf("Player 1: TYpE a number beTwEen 0 And 99 and PREss

 printf("%s",pictureRecor d[0].locat ion)
Th isis  mystru ct.
  typedefs truc t picture_Data
  {
   char *f ileN a me ;
   char*d es c r ipt io n; 
  c ha r* lo cat ion;
   int peop leC ou nt;
  }pic;It  doesn‘t w ork  and printin g m e Null  a s t h  loca tio n ofthe fi r st ele ment. Why ?C an som e body he l p  m e.
A:

The problem i s  t h at this line
s canf(" %s % s% s % d", pic _tmp.fileN am e, pi c _tmp.de s cr i p t ion ,  pic_tmp.loca tion, &pic_ t mp. people Co unt ) ;

ass umesth a t p ic.tmp hassuff icient sp ace al l ocatedf or file Name,des cri ptio n ,an d l oc a tio n .Non e  of  that is  t ru e, ho weve r , b ecau seallthree  fields remai n u nini t ial ized. 
In o rder  t o fix  this,  chan ge  the code to re ad s trings in toatem po raryb uffer,  an d t hen cop y it in t o d yn a m i ca lly allocated stri ng s . 
H ere is h ow you do  i t  for fil eN ame ; yo u needto d o  t he samethingf or  a ll thre e: 
chartm p_f ile Name[ 1 00]; 
chartmp_desc ripti o n[100];
char t m p_location[10 0 ]; s ca n f("% 99s %99s%99s%d" ,tmp _ file Name ,  t mp_ d escri ption ,t mp _ location, &pic_tmp. pe opleCo unt); 
pic_tmp.file Name = mal l o c (strlen( tmp_ f il e Name)+1);
strc py(pi c_tmp.file N ame, tmp _file Name);
. ..

You c a n  copy th e s tru ctwit h asingle assign m e nt,to o:
pict ure _Record [pi cNu mbe r]=pic_tmp;
Don't f or ge tto  ca ll fr e e on all  t hre emem berso f each  stru ct t oav o idmemoryl ea k s .

Q: 
Howtoma ke co de l o opback ar ound afte r a cond it io n of if , C guessingga me

I'm st uc k o n thep r oblem of  trying to make my code loop ba ckaroun d af ter a con dit ion.
I 'ma skingplayer  1 to  e nte r a num b e rbet we en 0 and 9 9 ,  if  they  e nter  anythi ng outside of that the  code shouldask  the m to  re t ry thi s. The p roblem is I hon estly have  n o  i dea how to ena bl e thatfrom my  code .  This i s what Ihave so f ar , Id o n't  understan d how to  throw aw hilel oo p inher e to h av e i t cir cle ba c k:  int  secre tn umber; 
  in tguesses; 

  printf("Player 1: T ype anumbe r b etween 0and 99and press 

 printf("%s",pictureRecord[0].location)

This_is my_struct.
  typedef struct_picture_Data
 _{
_ __char* fileName;
 _  char*_description;
   _char* location;
 __ int peopleCount;
  }pic;

It doesn‘t work and printing me Null as th location_of_the first_element._Why?_Can somebody help me.

A:

The problem_is that this line
scanf("%s%s%s%d",pic_tmp.fileName, pic_tmp.description,_pic_tmp.location, &pic_tmp.peopleCount);

assumes_that pic.tmp has sufficient space allocated for fileName,_description,_and location. None_of that is true, however, because all three fields_remain uninitialized.
In order to fix this,_change the code_to_read_strings into a temporary_buffer, and then copy it into_dynamically allocated strings.
Here is how you_do it for fileName; you need to_do the same thing for all_three:
char tmp_fileName[100];
char tmp_description[100];
char tmp_location[100];
scanf("%99s%99s%99s%d",tmp_fileName, tmp_description,_tmp_location, &pic_tmp.peopleCount);
pic_tmp.fileName_= malloc(strlen(tmp_fileName)+1);
strcpy(pic_tmp.fileName, tmp_fileName);
...

You can copy_the struct with_a single_assignment, too:
picture_Record[picNumber] =_pic_tmp;

Don't forget to call free on_all three members_of each struct to avoid memory_leaks.

_Q:

How to make_code_loop_back around_after a condition_of_if, C_guessing_game

I'm stuck on the problem of_trying_to make my code loop back around_after a condition.
I'm asking_player_1 to enter a_number between 0 and 99,_if they enter anything outside of_that the_code should_ask them to retry this. The problem is I honestly have_no idea how to enable that_from my code. This_is what_I_have so far,_I_don't understand_how to throw a while loop in_here to_have it circle back:
  int_secretnumber;
  int guesses;

__printf("Player 1: Type a number between_0 and 99 and press