dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

problema
Goto page 1, 2, 3  Next
 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Jan 29, 2006 3:00 pm    Post subject: problema

Code:
const char* car="Is not";

 char cars[64]; 
 sprintf(cars,"Car: %d ",car);
 TextOut(hdc, 350, 560, cars, 12);

Es gribu lai vins uzdruka "Car: Is not" Uz ekraana. bet vins uzdruka ciparus. Kas man ir jadara. Shitais variants neder vai arii es daru kaut ko nepareizi??
Back to top
View user's profile Send e-mail
anggelus



Joined: 23 Feb 2005
Posts: 383
Location: Rīga (LV)

PostPosted: Sun Jan 29, 2006 3:19 pm    Post subject:

Code:

char car[] ="Is not";

 char cars[64]; 
 sprintf(cars,"Car: %s ",car);

_________________
No comprendo lo que dice.
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Jan 29, 2006 3:22 pm    Post subject:

Paldies
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Jan 29, 2006 3:51 pm    Post subject:

Kāpēc cilvēki nekad neskatās dokumentācijā?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_printf_type_field_characters.asp
Code:
d    int    Signed decimal integer.
s    String    When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached.
Back to top
View user's profile Send e-mail
anggelus



Joined: 23 Feb 2005
Posts: 383
Location: Rīga (LV)

PostPosted: Sun Jan 29, 2006 4:11 pm    Post subject:

Varbūt angliski nesaprot Very Happy
_________________
No comprendo lo que dice.
Back to top
View user's profile Send e-mail
eXeM



Joined: 22 Mar 2005
Posts: 155
Location: Ape

PostPosted: Sun Jan 29, 2006 4:14 pm    Post subject:

itkaa jau tasi ir pashi pamati Very Happy
Back to top
View user's profile
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Jan 29, 2006 4:35 pm    Post subject:

Code:
 ofstream savefile ("save.sav");
  if (savefile.is_open())
  {
    savefile << car << endl;
    savefile.close();
  }

 ifstream savefile ("save.sav");
   if (savefile.is_open())
  { 
    savefile >> car;
    savefile.close();
  }


Kaapec piesienas pie rindinjas
Code:
savefile >> car;
nekompilejas
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Jan 29, 2006 4:43 pm    Post subject:

Mums jāzīlē kristāla bumbā kādu kļādu saka, un kāds ir car datu tips?
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Jan 29, 2006 4:51 pm    Post subject:

Kluuda:
ambiguous overload for 'operator>>' in 'savefile >> car'
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Jan 29, 2006 4:55 pm    Post subject:

Eh...
bubu wrote:
kāds ir car datu tips?


Pie tam: kā tu vari nodefinēt vienu un to pašu mainīgo (savefile) ar diviem dažādiem datu tipiem (ifstream un ofstream) viena scope ietvaros? Par to tev kompilētājs nelamājas?
Back to top
View user's profile Send e-mail
coderpp



Joined: 20 Aug 2005
Posts: 167
Location: Rīga, Koknese, Gajiena

PostPosted: Sun Jan 29, 2006 5:04 pm    Post subject:

Tie nav zem viena. Laikam man to pirmo iekopeet nevajadeja (ofstream)

vai tad shis nav tas tas data tips?
const char* car="Is not";
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Jan 29, 2006 5:08 pm    Post subject:

Tas ir datu tips (const char*). Bet to tu taču neuzrakstīji. Kā lai man bija zināt, ka jāskatās uz pirmo postu? :)

Bet atbilde ir - const nozīmē konstants, to nevar pamainīt! Tāpēc arī tu nevarēsi tur neko ielasīt. Tev ir jādefinē jauns char xx[111] buferis. Un jālasa tājā xxx, nevis vecajā const char* car. Tikai te atkal problēma ar bufera pārpildīšanos, ja failā gadīsies vairāk kā 111 simboli, tad programma labākajā gadījumā var vienkārši nokārties. Ja tu programmē C++, tad nelieto (vai vismaz lieto pēc iespējas mazāk) nekādus char*. Tā vietā lieto std::string klasi. Būs gan vieglāk darboties ar stringiem, gan mazāk jāraizējas par bufera pārpildīšanos.
Back to top
View user's profile Send e-mail
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Sun Jan 29, 2006 8:21 pm    Post subject:

Manupraat buutu vieglaak nevis defineet jaunu buferi (xxx[111]),bet vienkaarshi taa
Code:
const char* car="Is not";
vietaa rakstiit
Code:
char car[]="Is not";

Jo ka jau tev paskaidroja ieprieksh,tad const mainiigos nevar mainiit (kaa jau nosaukumaa mineets - const = konstante).Un tieshaam tev buutu labaak izmantot string klasi.Es pats gan vinju neizmantoju (ar vinju rodas daudz problemas),bet iesacejiem noteikti iesaku.
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Sun Jan 29, 2006 8:23 pm    Post subject:

Prtoams,ja tev vajag lielaku buferi,kaa 7 baiti ("Is not"+\0) ,tad bus jaraksta taa:
Code:
char car[345]="Is not";

kur 345 ir bufera lielums (burtos/baitos).
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Jan 29, 2006 9:25 pm    Post subject:

elvman wrote:
(ar vinju rodas daudz problemas),bet iesacejiem noteikti iesaku.

Piemēram?
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group