All pastes #730265 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-10-09 02:06 UTC
rendered paste body
#include "header.h"

print_result_by_chars(int charCount, char buffer[], int nonAlphaCharCount)
{
  int i;
  char buffer2[BUFSIZE];
  for(i = 0; i < charCount; i++)
  {
    buffer2[i] = buffer[i];
    if(isalpha(buffer[i]) == 0)
    {
	nonAlphaCharCount++;
    }
  }
  printf("num of lines is %d", charCount);
  printf("Line you entered was %s\n", buffer2);
  printf("Number of non-alphabetical Characters was %d\n", nonAlphaCharCount);
}

int main(int argc, char *argv[])
{
  struct args these_args;
  char ch;
  char *num_of_lines;
  char buffer[BUFSIZE];
  int charCount = 0;
  int nonAlphaCharCount = 0;
  int i;
  int fd_in;
  int fd_out;
  these_args = parse_input(argc, argv);
  fd_in = these_args.input_fd;
  fd_out = these_args.output_fd;
  num_of_lines = these_args.num_of_lines;
  if(strcmp(num_of_lines, "") != 0)
  {
    for(i = 1; i < strlen(num_of_lines); i++)
    {
      /* shift everything one character down */
      num_of_lines[i-1] = num_of_lines[i];
      /* terminate last character with null */
      if(i == (strlen(num_of_lines) - 1))
      {
        num_of_lines[i] = 0x00;
      }
    }
    charCount = atoi(num_of_lines);
  }
  if(fd_in != 0)
  {
    close(INPUT);
    dup(fd_in);
  }
  if(fd_out != 1)
  {
    close(OUTPUT);
    dup(fd_out);
  }
  /* read(fd_in, buffer, BUFSIZE); */
  scanf("%s", buffer);
  if(strcmp(num_of_lines, "") == 0)
  {
    print_result_by_chars(strlen(buffer), buffer, nonAlphaCharCount);
  }
  else
  {
    print_result_by_chars(charCount, buffer, nonAlphaCharCount);
  }
}