0

Please see the post

Given the below data in the file:

Jim: 100.00 Amed

John: 200.00
if (line[len] != '\0') {                    
    printf("extra characters: %s\n", line + len);
}

the first invalid line will be:

Jim: 100.00 Amed

and the len 12 and the output will be:

extra characters: Amed

How does line + len give:

Amed
Harith
  • 4,663
  • 1
  • 5
  • 20

1 Answers1

1

line + len will increment line's value (a memory address) by the size of its underlying data type.

So if line originally was:

Jim: 100.00 Amed

line + 12 would evaluate to:

Amed

See also: Pointer Arithmetic and c-faq.com section 4

Harith
  • 4,663
  • 1
  • 5
  • 20