---
title: "Fel"
type: "forum-thread"
url: "https://www.webforum.nu/amne/c-cpp/68657-fel"
topic: "C/C++"
topic_url: "https://www.webforum.nu/amne/c-cpp"
author: "Alpha II"
published: "2003-02-18T17:03:12.000Z"
updated: "2003-02-18T21:28:43.000Z"
replies: 5
views: 246
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/c-cpp/68657-fel"
---

# Fel

## #1 — Alpha II, 2003-02-18T17:03Z

Förstår inte varför jag får fel :l

```
void LoadGame()
{
	// Texturer
	char dir[] = "\data\textures\";
	LoadTGA(textures[TEX_SPACESHIP],dir + "spaceship.tga");
	LoadTGA(textures[TEX_ASTEROID],	dir + "asteroid.tga");
	LoadTGA(textures[TEX_MISSILE],	dir + "missile.tga");
}
```

Fel \~

> Error E2380 load.cpp 4: Unterminated string or character constant in function LoadGame()
> Error E2141 load.cpp 5: Declaration syntax error in function LoadGame()
> Error E2085 load.cpp 6: Invalid pointer addition in function LoadGame()
> Error E2034 load.cpp 6: Cannot convert 'TextureImage' to 'TextureImage \*' in function LoadGame()
> Error E2342 load.cpp 6: Type mismatch in parameter 'texture' (wanted 'TextureImage \*', got 'TextureImage') in function LoadGame()
> Error E2085 load.cpp 7: Invalid pointer addition in function LoadGame()
> Error E2034 load.cpp 7: Cannot convert 'TextureImage' to 'TextureImage \*' in function LoadGame()
> Error E2342 load.cpp 7: Type mismatch in parameter 'texture' (wanted 'TextureImage \*', got 'TextureImage') in function LoadGame()
> Warning W8004 load.cpp 9: 'dir' is assigned a value that is never used in function LoadGame()

Permalänk: https://www.webforum.nu/p/68657

## #2 — juventus1, 2003-02-18T17:34Z

En gissning: Den gillar inte char dir\[\] = "\\data\\textures\\"; Prova med detta istället: 

```
char dir[] = "\\data\\textures\\";
```

Permalänk: https://www.webforum.nu/p/953643

## #3 — Alpha II, 2003-02-18T18:31Z

> Error E2085 load.cpp 5: Invalid pointer addition in function LoadGame()
> Error E2034 load.cpp 5: Cannot convert 'TextureImage' to 'TextureImage \*' in fun
> ction LoadGame()
> Error E2342 load.cpp 5: Type mismatch in parameter 'texture' (wanted 'TextureIma
> ge \*', got 'TextureImage') in function LoadGame()
> Error E2085 load.cpp 6: Invalid pointer addition in function LoadGame()
> Error E2034 load.cpp 6: Cannot convert 'TextureImage' to 'TextureImage \*' in fun
> ction LoadGame()
> Error E2342 load.cpp 6: Type mismatch in parameter 'texture' (wanted 'TextureIma
> ge \*', got 'TextureImage') in function LoadGame()
> Error E2085 load.cpp 7: Invalid pointer addition in function LoadGame()
> Error E2034 load.cpp 7: Cannot convert 'TextureImage' to 'TextureImage \*' in fun
> ction LoadGame()
> Error E2342 load.cpp 7: Type mismatch in parameter 'texture' (wanted 'TextureIma
> ge \*', got 'TextureImage') in function LoadGame()
> Warning W8004 load.cpp 9: 'dir' is assigned a value that is never used in functi
> on LoadGame()

```

void LoadGame()
{
	// Texturer
	char dir[] = "\\data\\textures\\";
	LoadTGA(textures[TEX_SPACESHIP],dir + "spaceship.tga");
	LoadTGA(textures[TEX_ASTEROID],	dir + "asteroid.tga");
	LoadTGA(textures[TEX_MISSILE],	dir + "missile.tga");

}
```

Permalänk: https://www.webforum.nu/p/953682

## #4 — UlfT, 2003-02-18T18:43Z

Strängarna borde du slå ihop med:
strcat( dir, "spaceship.tga" )
vilket du kan göra inne i funktionsanropen till "LoadTGA". Den andra delen kan jag inte hjälpa så mycket med eftersom jag inte vet vad "TextureImage" är, men tydligen ska du skicka en pekare till en sådan. Nu skickar du tydligen hela structen i sig själv.

Permalänk: https://www.webforum.nu/p/953688

## #5 — Phorpher, 2003-02-18T18:43Z

dir är en C-sträng. Inte en string. Du kan inte använda plusoperatorn på en C-sträng på det där sättet.

Kolla lite på strcpy() och strcat()...

UlfT var först såg jag. Men kom ihåg att du inte kan använda den char-array (dir) du har nu med strcat. 

När du deklarerar den såhär: 

```
char dir[] = "\\data\\textures\\";
```

 
så allokeras bara precis så mycket minne som strängen behöver. 

För att få plats med filnamnet efter så får du skapa en temporär char-array som är tillräckligt stor för att få plats med alla tecken.

Permalänk: https://www.webforum.nu/p/953690

## #6 — Alpha II, 2003-02-18T21:28Z

Funkar utmärkt! Iaf den delen :D

Programmet kraschar när man startar det :( Men det problemet ligger nog någon annanstans...

Permalänk: https://www.webforum.nu/p/953816

---

Tråden på webben: https://www.webforum.nu/amne/c-cpp/68657-fel
