All pastes #832386 Raw Edit

Untitled

public c v1 · immutable
#832386 ·published 2007-12-26 03:57 UTC
rendered paste body
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>int validate(char * str, char * output);int main() {  FILE *fp;  FILE *fo;  char str[255]="";  char output[19]="";  int status=0;  if ((fp=fopen("input.txt","r"))==NULL)   {     printf("Error\n");     exit(1);   }  if ((fo=fopen("output.txt","w"))==NULL)  {   printf("Error\n");   exit(1);  }  while(!feof(fp))   {    fgets(str, 253, fp);    if (validate(str, output)==0)        {                fputs(output, fo);        }   }  fclose(fp);  fclose(fo);  return 0; }int validate(char * str, char output[13]){  char mac[13]="";  int j=0;  int i=0;  for (i=0; i<strlen(str); i++)   if (isxdigit(str[i]))    if (j<12)     {mac[j]=toupper(str[i]);      j++;     }    else     {      j=0;      break;     }  mac[j]='\0';  if (j!=12)   {    printf("Not valid mac adress\n");    return 1;   }  else   {     j=0;     for (i=0; i<strlen(mac); i++)      {       output[j]=mac[i];       if ((i+1)%2==0 && i<11)        {                j++;                output[j]=':';        }       j++;      }    }  return 0; }