Splitting response from AT command into variables

Hi.

I'm not too well versed in C++, so forgive me for this simple question. I send AT-command to my Ublox GSM module, and want to parse the response so I can get the bytes from a file read. Below is the response I want to split. I was thinking of using sscanf, but not sure how to do it. All help is very much appreciated.

Command:
AT+URDBLOCK="update-v12.txt", 0, 200

Response:

char *response;

+URDBLOCK: "update-v12.txt",200,"0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-"

My attempt that does not work:

char imeiResponse[200];
char filename[14];
int sz;

sscanf(response, "\r\n+URDFILE: \"%c\",%d,\"%c\"", filename, &sz, Response)

How do you think this could work ?

Response:

+[color=red]URDBLOCK[/color]: "update-v12.txt",200,"0....

My attempt that does not work

sscanf(response, "\r\n+[color=red]URDFILE[/color]: ...

Below is the response I want to split.

+URDBLOCK: "update-v12.txt",200,"0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-"

How do you want to split this response?

Learn to use strtok(). It will easily parse that string into individual tokens.

Well, you can do it and it is not that dissimilar to your own attempt:

char response[300] = { "+URDBLOCK: \"update-v12.txt\",200,\"0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-\"" }  ;  // added some escaped quotes.
char commandName[50] ;
char fileName[50] ;
int16_t returnCode ;
char payload[300] ;

void setup() {
  Serial.begin(115200) ;
  Serial.println( "starting..." ) ;

  sscanf( response, "%s \"%[^\"]\",%d,\"%[^\"]%*s" , commandName , fileName , &returnCode, payload ) ;

  Serial.print(">") ; Serial.print( commandName ) ; Serial.println("<") ;
  Serial.print(">") ; Serial.print( fileName ) ; Serial.println("<") ;
  Serial.print(">") ; Serial.print( returnCode ) ; Serial.println("<") ;
  Serial.print(">") ; Serial.print( payload ) ; Serial.println("<") ;
}

void loop() {
}

output:

starting...
>+URDBLOCK:<
>update-v12.txt<
>200<
>0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-<

The syntax is somewhat similar to that of a very restricted regular expression and not very intuitive. I had to play a bit to get it to work.
You could get buffer overflows if fails to find the tokens you are expecting. There are tricks, though, to get round this and also to optimise the buffer space required by using multiple scans. See: c - read comma-separated input with `scanf()` - Stack Overflow
Anyway, the advice to look at strtok() is probably quite wise.

6v6gt:
Anyway, the advice to look at strtok() is probably quite wise.

that could look something like this:

char answerBuffer[] = "+URDBLOCK: \"update-v12.txt\",200,\"0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-\"";

const char* delimiters = "\",-";

void setup() {
  Serial.begin(115200);

  size_t count = 0;
  if (strncmp(answerBuffer, "+URDBLOCK: \"", 12) == 0) { // starts with '+URDBLOCK: "'
    char * pch = strchr(answerBuffer + 12, '\"');
    if (pch) *pch = '\0';
    Serial.print(F("FileName = "));
    Serial.println(answerBuffer + 12);

    pch = strtok (pch + 1, delimiters);
    while (pch != NULL)
    {
      if (!strchr(delimiters, *pch)) { // skip over two adjacent delimiters
        Serial.print(F("@ position ["));
        Serial.print(count++);
        Serial.print(F("]\tI found ==> '"));
        Serial.print(pch);
        Serial.println(F("'"));
      }
      pch = strtok (NULL, " ,.-");
    }
  }
}

void loop() {}

Serial Monitor (@ 115200 bauds) will show

[color=purple]
FileName = update-v12.txt
@ position [0 ]	I found ==> '200'
@ position [1]	I found ==> '1'
@ position [2]	I found ==> '2'
@ position [3]	I found ==> '3'
@ position [4]	I found ==> '4'
@ position [5]	I found ==> '5'
@ position [6]	I found ==> '6'
@ position [7]	I found ==> '7'
@ position [8]	I found ==> '8'
@ position [9]	I found ==> '9'
@ position [10]	I found ==> '10'
@ position [11]	I found ==> '11'
@ position [12]	I found ==> '12'
@ position [13]	I found ==> '13'
@ position [14]	I found ==> '14'
@ position [15]	I found ==> '15'
@ position [16]	I found ==> '16'
@ position [17]	I found ==> '17'
@ position [18]	I found ==> '18'
@ position [19]	I found ==> '19'
@ position [20]	I found ==> '20'
@ position [21]	I found ==> '21'
@ position [22]	I found ==> '22'
@ position [23]	I found ==> '23'
@ position [24]	I found ==> '24'
@ position [25]	I found ==> '25'
@ position [26]	I found ==> '26'
@ position [27]	I found ==> '27'
@ position [28]	I found ==> '28'
@ position [29]	I found ==> '29'
@ position [30]	I found ==> '30'
@ position [31]	I found ==> '31'
@ position [32]	I found ==> '32'
@ position [33]	I found ==> '33'
@ position [34]	I found ==> '34'
@ position [35]	I found ==> '35'
@ position [36]	I found ==> '36'
@ position [37]	I found ==> '37'
@ position [38]	I found ==> '38'
@ position [39]	I found ==> '39'
@ position [40]	I found ==> '40'
@ position [41]	I found ==> '41'
@ position [42]	I found ==> '42'
@ position [43]	I found ==> '43'
@ position [44]	I found ==> '44'
@ position [45]	I found ==> '45'
@ position [46]	I found ==> '46'
@ position [47]	I found ==> '47'
@ position [48]	I found ==> '48'
@ position [49]	I found ==> '49'
@ position [50]	I found ==> '50'
@ position [51]	I found ==> '51'
@ position [52]	I found ==> '52'
@ position [53]	I found ==> '53'
@ position [54]	I found ==> '54'
@ position [55]	I found ==> '55'
@ position [56]	I found ==> '56'
@ position [57]	I found ==> '57'
@ position [58]	I found ==> '58'
@ position [59]	I found ==> '59'
@ position [60]	I found ==> '60'
@ position [61]	I found ==> '61'
@ position [62]	I found ==> '62'
@ position [63]	I found ==> '63'
@ position [64]	I found ==> '64'
@ position [65]	I found ==> '65'
@ position [66]	I found ==> '66'
@ position [67]	I found ==> '67'
@ position [68]	I found ==> '68'
@ position [69]	I found ==> '69'

[/color]

Thank you everyone for great suggestions! I used the approach suggested by 6v6gt.