• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
konwersja string do tablicy char
#1
Witam problem jak w temacie potrzebuje stwozyc tako kowersje do odczytu kodu szesnastkowego
Kod:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0x18, 0x0C, 0x46, 0x27, 0x07, 0x07, 0x03, 0x03, 0x03,
0x03, 0x03, 0x21, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x00, 0x10,
0x10, 0x18, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x11, 0x13, 0x07, 0x27, 0x46, 0x0C, 0x98, 0x30,
0x60, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x30, 0x70, 0x78, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x3E, 0xC1,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0xFC, 0xFC, 0xFC, 0x78, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xCE, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x02, 0x04, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x84, 0x44, 0x62, 0x23, 0x11, 0x10, 0x10,
0x00, 0x00, 0x00, 0x10, 0x11, 0x22, 0x64, 0x4C, 0x8C, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10,
0x18, 0x08, 0x08, 0x0C, 0x0C, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x19, 0x60, 0xE0,
0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x60, 0x18, 0x0E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFF,

który zapisany jest w txt na karcie sd ,po odczycie z niej jest to ciąg znaków string i tu potrzebuje przenieść to z 1 zmiennej do osobnych komórek char (char nie ma zdefiniowanej wielkości dana char(){}Wink
ale po wpisaniu dana[20]; che odczytać wartość z 20 znaku (tablica 1 wymiarowa).
Macie jakiś pomysł na rozwiązanie tego problemu konwersja stringtocharArray(char) wpisuje do 1 komórki wszystko (a dokładnie do komórki dana [0] ).
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
#2
o to wypociny dzisiejszej nocy udało mi się odczytać dane do osobnych kolumn i oto właśnie mi chodziło ale jest problem ze to zmienna string jak zrobić konwersje do char
Kod:
#include <SPI.h>
#include <SD.h>

File myFile;
char dana;
String bufor;
char buforst[504];




long i;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
                     for(int b=0;b<4;b++){
                            dana=myFile.read();
                            bufor=bufor+String(dana);
                          
                                }
                                 Serial.println(bufor);
                               i++;
                          //     buforst[i]=bufor;
                          Serial.println(i);
                                bufor.toCharArray(buforst, 504) ;
                            //   buforst[i]=char(bufor);
                              
                                bufor="";
                          
                               }
                               for(int b=0;b<504;b++){
                               Serial.println(buforst[b]);
                               }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
   }
}

void loop() {
  // nothing happens after setup
}
pomoże ktos
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości