Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

char[255] in double

Empfohlene Antworten

Veröffentlicht

Moin Leute

Wie kann ich char[255] in double werte umwandeln??

char[255] enthält nur Zahlen und als trennzeichen zum bereich <0 einen Punkt.

MfG Hubi

Also, wenn Du in der einen Character Variablen mehrere Zahlen hast, die alle in Double Werte umgewandelt werden sollen, musst Du den STring zuerst zerlegen. Das kannst Du mit

char *strtok( char *strToken, const char *strDelimit );

Example

/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/

#include <string.h>
#include <stdio.h>

char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;

void main( void )
{
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}[/PHP]

tun. Zum umwendeln des Characters in einen Doubel Wert nimmst Du dann

[PHP]double atof( const char *string );

Bine

Hi,

zum Umwandeln von Zeichenketten in double, bzw. float-Werte kannst Du die Funktion "atof" aus der <math.h> nehmen. Allerdings dürfte dabei einiges an Präzision verloren gehen.

Vielleicht verstehe ich aber auch nicht wirklich, was Du eigentlich machen willst. In einem char-Array mit 255 Stellen könntest Du riesige "Zahlen" speichern (eben mit 254 Stellen + binäre Null ;)). Brauchst Du das wirklich?

Und was meinst Du mit "Punkt als Trennzeichen zum Bereich <0"? Das wird doch meines Erachtens mit einem Minus am Anfang gesetzt... :confused: Oder meinst Du die Nachkommastellen?

DocMabuse

Danke Danke

es läuft jetzt.

Schönen Tag und schönes WE noch.

Wie hast Du es denn nun gemacht?

Bine

Ich habe es so gemacht wie du es mir vorgeschlagen hast.

Mit: double atof (const char *string);

und das klappt wunderbar, danke nochmal

MfG Hubi

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.