Strings in array - sscanf
#1

I do not understand the use of strings in array, do not know really like is used.

pawn Код:
sscanf ("hello", "a <s [5]> [10]", arr);
the above code would not work.
Can anyone explain me the use of this?
Reply
#2

me too i search more explication about this i found this

PHP код:
main ()
{
  new 
test []="Azula is 15 years ";
  new 
text [20];
  new 
i;
  
sscanf (test,"%s %d",text,&i);
  
printf ("%s -> %d\n",text,i);
  return 
0;

my code should print Azula 15 but dosent work
Reply
#3

@Azula:
Sample:
Код:
main ()
{
  new test[20]="Azula is 15 years ";
  new text[20];
  new i;
  sscanf (test,"s[20]{s[20]}i",text,i);
  printf ("%s -> %d\n",text,i);
  return 0;
}
Your mistake was:
Код:
sscanf (test,"%s %d",text,&i);
Right:
Код:
 sscanf (test,"s[20]{s[20]}i",text,i);
{s[20]}>>> Thats to skip the string "is " in you sample

For more Question u can PM me
Reply
#4

thanks you but still dosent work (compile fine) it dosent print anythings
Reply
#5

Ok sry but for me it works.
Quote:

[21:05:07] Azula -> 15

Reply
#6

pawn Код:
new array[] = "hello CrashCar how are you";
new arr[5][8]; // 5 arrays each up to 8 characters long (7 + NULL).
sscanf(array, "a<s[8]>[5]", arr);

for(new i=0; i != sizeof(arr); i++)
    print(arr[i]);
should show

pawn Код:
hello - arr[0]
Crashcar - arr[1]
how - arr[2]
are - arr[3]
you - arr[4]
I have never use this so I could be wrong
Reply
#7

Thanks !.

I will discuss this here, not to make a new topic. Why does the code does not work ?.

What use is the code?:

pawn Код:
new array[2];
    new integer;

    sscanf(array,"A<i>(0,2)[2]",integer);

    print(array);
Reply
#8

pawn Код:
new array[2];
new integer[2];

sscanf(array,"A<i>(0,2)[2]",integer);

printf("integer[0] = %d\ninteger[1] = %d",integer[0],integer[1]);
Reply


Forum Jump:


Users browsing this thread: