6月11-15号-check-检查输入字符串的正确性

来源:互联网 发布:下载gif软件 编辑:程序博客网 时间:2024/04/28 18:46

检查-i和-o后面的字符串的正确性!

 

 

#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include <windows.h>

bool check(char str[]);

main()
{
 char a[100]="",str[100]="";
   int i=0,j=0;
   bool f=false;  
    while(!f)
 {
   cin.clear();
     cin.getline(a,100);
  
// while(a[i])
// {
//  if(a[i]==' ')i++;
//  str[j++]=a[i++];
  
// }//qu diao kong ge
 f=check(a);
    // cout<<f<<endl;
   }
 
   //cin.clear();
      //cin.getline(a,100);
  // cout<<a<<endl;
  // cin.clear();
     //cin.getline(a,100);
  //cout<<a<<endl;j

 //cout<<str<<endl;
 
}

bool check(char str[])
{
 char in[50]="",out[50]="";
 int i=0,j=0,k=0,b[2]={0},flag=0;
 while(str[i])
 {
  if(str[i]==' ')i++;
  if(str[i]=='-')
  {
   i++;
   if(str[i]=='I'||str[i]=='i')
   {
    b[0]++;
     i++;
     while(str[i]!='-'&&str[i])
     {
     if(str[i]==' '&&str[i+1]!='-') i++;
                    in[j++]=str[i++];
       //cout<<in<<endl;
     }
      i--;
    if(b[0]==2)
    {
     cout<<"command error! please put in again"<<endl;
           return false; //b[0]=0;
     //i=0;モテflagタエア・ヌネサコルハ菠・
        //cin.clear();
     //cin.getline(a,100);    
    }
   }
   else if(str[i]=='O'||str[i]=='o')
            {
      b[1]++;
         i++;
     while(str[i]!='-'&&str[i])
     {
     if(str[i]==' '&&str[i+1]!='-')i++;
                   out[k++]=str[i++];
     }
      i--;
    if(b[1]==2)
    {
     cout<<"command error! put in again"<<endl;
                    return false;

    }
   }
   //else if(a[i]==' ')
   //{
   // i++;
   //}
       else
   {
    cout<<"command error! put in again!"<<endl;
    return false;
   }
  }
     // in[j++]=a[i];
  i++;
 }
 
    k=0;j=0;
 fstream file;
    while(in[j])
 {
  if(in[j]=='.')
  {
      flag=1; 
      if((in[j+1]=='P'&&in[j+2]=='R'&&in[j+3]=='J')||(in[j+1]=='p'&&in[j+2]=='i'&&in[j+3]=='j'))
   {   cout<<"yes!"<<endl;
               file.open(in,ios::in);
             if(!file)
    {
     cout<<"file is not exist ! put in again!"<<endl;
     return false;
    }
                 else cout<<"file is exist!"<<endl;
   }
            else
   {
    cout<<"file is wrong put in again!"<<endl;
       return false;
   }
  }
  
  j++;
 }
 if(flag==0)
 {
  cout<<"in file is wrong!put in again"<<endl;
  return false;
 }
 
 while(out[k])
 {
      if(out[k]=='.')
   {
        cout<<"file jia is wrong put in again!"<<endl;
  return false;
   }
   k++;
 }
   
 if(out[0]=='\0')
 {
  //cout<<out<<endl;
   GetCurrentDirectory(100,out) ;//如果没有入力就 默当前路径
 }
    else
 {
      WIN32_FIND_DATA  wfd;
      HANDLE hFind = FindFirstFile(out, &wfd);
      if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes &&FILE_ATTRIBUTE_DIRECTORY))
   {
         cout<<"directory is  exist"<<endl;
   }
   else
   {
  cout<<"directory is not exist put in again!"<<endl;
  return false;
   }  
    FindClose(hFind);
    }
 
  
// cout<<a<<endl;
    cout<<in<<endl;
 cout<<out<<endl;
 cout<<i<<endl;
 return true;
}


 

原创粉丝点击