How to rewrite this code so I don't need str1 and str2 (i.e. no conversion)
Code:
#include<conio.h>
#include<stdio.h>
#include <string.h>
char str1[10];
char str2[10];
void writeDes(char str1[],char str2[]);
int main(void)
{
char name[10];
char code[10];
char *p;
fgets(name, sizeof(name), stdin );
if ( (p=strchr(name,'\n')) != NULL ) *p = '\0';
char *str1 = name;
fgets(code, sizeof(code), stdin );
if ( (p=strchr(code,'\n')) != NULL ) *p = '\0';
char *str2 = code;
writeDes(str1,str2);
return 0;
}
void writeDes(char str1[],char str2[])
{
printf(str1);
printf("\n");
printf(str2);
}
I am new to C and am finding passing parameters to functions a bit difficult, so this is a test program. It does work but I would like to do away with having to convert name and code to str1 and str2. I want only to use name and code. Thank you, zach.