Re: function pointers



hifrnds007@xxxxxxxxx wrote in comp.lang.c:

how the function poiners avoids the usage of switch cases?

Here's a typical switch statement:

switch (user_input)
{
case 0: DeleteFile(); break;
case 1: CopyFile(); break;
case 2: RenameFile(); break;
case 4: MoveFile();
}

And here's the function pointer equivalent:

void (*const funcs[4])(void) = {DeleteFile,CopyFile,Renamefile,MoveFile};

funcs[user_input];

--
Tomás Ó hÉilidhe
.



Relevant Pages

  • Re: function pointers
    ... switch ... case 1: CopyFile(); break; ... case 2: RenameFile(); break; ... And here's the function pointer equivalent: ...
    (comp.lang.c)
  • Rename file
    ... copyfile, movefile). ... Yet, there is no "renamefile". ... missing something here or is it so trivial to write an own ...
    (comp.soft-sys.matlab)
  • Re: Rename file
    ... copyfile, movefile). ... Yet, there is no "renamefile". ... missing something here or is it so trivial to write an own ...
    (comp.soft-sys.matlab)