How to clear a buffer for use again in a for loop?

Each time the for loop runs, buf grows. How can I clear it? memset doesn't work, and I can't set buff to "" So how? It must be simple.

#include <Arduino.h>

void setup () {
Serial.begin(19200);
Serial.println("start");
DisplayLogFiles();
} //end setup

void loop() {} //do nothing more

void DisplayLogFiles() {
int yr = 12;
char fName[11], buf[20];

for(int k = 0; k < 5; k++) {
Serial.println(k);
itoa(yr, buf, 10);
strcat(fName, buf);
Serial.println(fName);
memset(&buf[0], 0, sizeof(buf));
}
} //end DisplayLogfiles

memset doesn't work

It doesn't?

Forget it. Stupid question; it is fName that needs memset. Sorry.

memset works, and strcat works, but you have to use them in the right way

STRCAT(3)                  Linux Programmer's Manual                 STRCAT(3)

NAME
       strcat, strncat - concatenate two strings

SYNOPSIS
       #include <string.h>

       char *strcat(char *dest, const char *src);

       char *strncat(char *dest, const char *src, size_t n);

DESCRIPTION
       The  strcat() function appends the src string to the dest string, over?
       writing the terminating null byte ('\0') at the end of dest,  and  then
       adds  a  terminating  null  byte.  The strings may not overlap, and the
       dest string must have enough space for the  result.   If  dest  is  not
       large  enough, program behavior is unpredictable; buffer overruns are a
       favorite avenue for attacking secure programs.

So what you have is copying buf (up to 20 characters) into the end of fName (up to 11 characters), which, according to my maths, is not a good idea at best.

Plus you have to ask yourself: "What is fName?"

And the answer is: "Who the hell knows?"

At the start of the function it contains whatever might have been in the 11 byte area of memory it occupies, and then on each iteration of the loop it's going to get the contents of buf added to the end of it.

A better option for what I think you are trying to do, would be to use snprintf:

void DisplayLogFiles() {
  int yr = 12;
  char fName[11];
  
  for(int k = 0; k < 5; k++) {
      Serial.println(k);
      snprintf(fName, 10, "file%d.%d.", yr, k);
      Serial.println(fName);
  }
} //end DisplayLogfiles

which would (though quite if it's what you want I have no idea) give you:

0
file12.0
1
file12.1
2
file12.2
3
file12.3
4
file12.4

Adjust your snprintf, and the parameters, to suit your needs.