-
-
Save alastairparagas/1b5efd945a955812e542a26f20f73bce to your computer and use it in GitHub Desktop.
| // return 1 if the file name is illegal; otherwise, return 0; legal | |
| // characters for a file name include letters (case sensitive), | |
| // numbers, dots, dashes, and underscores; and a legal file name | |
| // should not be more than MAX_NAME-1 in length | |
| static int illegal_filename(char* name) | |
| { | |
| /* YOUR CODE */ | |
| return 1; | |
| } |
static int illegal_filename(char* name)
{
flag = 0;
for(int i = 0; name[i]; i++){
if((name[i] >= 'a' && name[i]<= 'z') || (name[i] >= 'A' && name[i] <= 'Z'))
{
flag = flag+ 0;
}
else if(name[i] >= '0' && name[i] <= '9')
{
flag = flag+ 0;
}
else if ((name[i] =='.' )| (name[i] =='-' )|(name[i] =='_' ))
{
flag = flag + 0;
}
flag =flag + 1;
}
if (strlen(name) > MAX_NAME-1)
{
flag = flag + 1;
}
if (flag == 0 ){
return 0;
}
return 1;
}
static int illegal_filename(char* name)
{
for(int i = 0; i < strlen(name); i++) {
printf("Current char: '%c'\n", name[i]);
if((name[i] >= 'a' && name[i]<= 'z') || (name[i] >= 'A' && name[i] <= 'Z')){
continue; //if the char is in the alphabet, whether uppercase or lowercase
// continue to the next iteration
}
else if(name[i] >= '0' && name[i] <= '9'){
continue; //if the char is a number, continue to the next iteration
}
else if ((name[i] =='.' ) || (name[i] =='-' ) || (name[i] == '_' )) {
continue; //if the char is a .,_,- , continue to the next iteration
}
else {
printf("no");
return 1; //if the char isn't in the three cases above, then the filename is
//illegal
}
}
if (strlen(name) > MAX_NAME-1){ //name of file greater than max_name-1 means it is
printf("no"); //illegal
return 1;
}
printf("yes");
return 0;
}
static int illegal_filename(char* name) {
// Iterate over each character of the input file name
for(int i = 0; i< strlen(name); i++) {
if((name[i] >= 'a' && name[i]<= 'z') || (name[i] >= 'A' && name[i] <= 'Z')){
continue;
//if the char is in the alphabet, whether uppercase or lowercase
//continue to the next iteration
}
else if(name[i] >= '0' && name[i] <= '9'){
continue; //if the char is a number, continue to the next iteration
}
else if ((name[i] =='.' ) || (name[i] =='-' ) || (name[i] == '' )) {
continue; //if the char is a .,,- , continue to the next iteration
}
else {
return 1;
//if the char isn't in the three cases above, then the filename is illegal
}
}
//name of file greater than max_name-1 means it is illegal
if (strlen(name) > MAX_NAME-1){
return 1;
}
return 0;
}
static int illegal_filename(char* name) {
// Iterate over each character of the input file name
for(int i = 0; i< strlen(name); i++) {
if((name[i] >= 'a' && name[i]<= 'z') || (name[i] >= 'A' && name[i] <= 'Z')){
continue;
//if the char is in the alphabet, whether uppercase or lowercase
//continue to the next iteration
}
else if(name[i] >= '0' && name[i] <= '9'){
continue; //if the char is a number, continue to the next iteration
}
else if ((name[i] =='.' ) || (name[i] =='-' ) || (name[i] == '_' )) {
continue; //if the char is a .,_,- , continue to the next iteration
}
else {
return 1;
//if the char isn't in the three cases above, then the filename is illegal
}
}
//name of file greater than max_name-1 means it is illegal
if (strlen(name) > MAX_NAME-1){
return 1;
}
return 0;
}
static int illegal_filename(char* name)
{
flag = 1;
for(int i = 0; name[i]; i++){
if((name[i] >= 'a' && name[i]<= 'z') || (name[i] >= 'A' && name[i] <= 'Z'))
{
flag = 0;
}
else if(name[i] >= '0' && name[i] <= '9')
{
flag = 0;
}
else if ((name[i] =='.' )| (name[i] =='-' )|(name[i] =='_' ))
{
flag = 0;
}
flag = 1;
}
if (strlen(name) > MAX_NAME-1)
{
flag = 1;
}
return flag;
}