예제 #1
0
/* Delete the character under the cursor */
static void
delchr(int del, char *curline, int line_len)
{
   int i, cnt;

   if (cp > cl || del == 0) {
      return;
   }
   while (del-- && cl > 0) {
      cnt = char_count(cp, curline);
      if ((i=cl-cp-cnt) > 0) {
         memcpy(&curline[cp], &curline[cp+cnt], i);
      }
      cl -= cnt;
      curline[cl] = EOS;
      t_clrline(0, t_width);
      i = 0;
      while (cl > cp) {
         forward(curline, line_len);
         i++;
      }
      while (i--) {
         backup(curline);
      }
   }
}
예제 #2
0
int main(int argc, char *argv[]) {
  /*
   * BONUS: Who is often credited with this quote?
   */
  char msg[] =
    "Everything should be made as simple as "
    "possible, but not simpler.";


  printf("Number of o's: %d\n", char_count(msg, 'o'));

  /*
   * Q9: How many NULL characters will be found?
   */
  printf("Number of NULL characters: %d\n", char_count(msg, '\0'));

  return 0;
}
예제 #3
0
파일: TEXTVALA.CPP 프로젝트: NixonZ/Cpp-Z
void main()
{
 clrscr();
 ofstream fout("poem.txt",ios::trunc);
 fout<<"if you are not willing to learn,\n "
     <<"No one can help you.\n "
     <<"If you are determined to learn,\n "
     <<"No one can stop you.";
 fout.close();
 int x;
 do
 {
  cout<<"\n1-Display file\n2-lower case to upper case\n3-total character\n4-no of words\n5-Average word size\n6-no of lower case and upper case\n7-vowels\n8-no of words starting with I\n9-no. of lines ending with '.'\n10-exit\n";
  cin>>x;
  switch(x)
  {
   case 1:display();
	  break;
   case 2:lowertoupper();
	  cout<<"\nFile with lower to upper\n";
	  display();
	  break;
   case 3:cout<<"\nNo. of characters="<<char_count();
	  break;
   case 4:cout<<"\nNo. of words="<<wordcount();
	  break;
   case 5:cout<<"\nAverage word size=" <<(float)(char_count())/(float)(wordcount());
	  break;
   case 6:lowercount_uppercount();
	  break;
   case 7:cout<<"\n\nVowels in the file are\n";
	  vowels();
	  break;
   case 8:cout<<"\nNo. of words starting with I=" <<counti();
	  break;
   case 9:cout<<"\nNo. of lines ending with \'.\'=" <<dotcount();
	  break;
   case 10: break;
   default: cout<<"Wrong input\n";
  }
 }while(x!=10);
}
int main()
{
	int i;
	for (i = 0; i < 4; i++)
	{
		char_count(tests[i].input);
		check_result(tests[i].input, tests[i].expected_op);
	}
	getchar();
	return 0;
}
예제 #5
0
StringArray *load_topwords(const char *lang) {
    int i = 0;
    char *path = topwords_file(lang);
    char *content = read_file(path);
    int words_count = char_count(content, ' ') + 1;
    char *pch;
    StringArray *sarray = create_string_array(words_count);
    sarray->items = (char**) safe_malloc(sizeof(char*) * words_count);
    for (pch = strtok(content, " "); pch != NULL; pch = strtok(NULL, " ")) {
        sarray->items[i++] = pch;
    }
    free(path);
    // 'content' cannot be freed, because of strtok
    return sarray;
}
예제 #6
0
char *hex2str(char *str) {
    char *shellcode= str_replace(str_replace(str, "\\x", " "), "0x", " ");
    char *pEnd;
    long int j = strtol(shellcode, &pEnd, 16);
    char *sc;
    sc = malloc(strlen(shellcode)-char_count(shellcode, ' '));
    int counter=0;
    while (j != 0) {
       sprintf(sc+counter*sizeof(char), "%c", (int) j);
        counter++;
        j = strtol(pEnd, &pEnd, 16);
    }
    free(shellcode);
    return sc;
}
예제 #7
0
/*------------------ DELIM_COUNT -------------------*/
int delim_count(char * data, char ca, int lim, int * sta, int *sto)
{
int co, max, maxlen, count, ret;
maxlen = (int)strlen(data);
max = char_count(data, ca);
count = 0;

for(co = 0; co < maxlen; co++){
   if(ca == data[co]){
      if(count == (lim - 1)){
         if(co == 0){
            * sta = co;
            }
         if(co > 0){
            * sta = co + 1;
            }
         }
      if(count == lim){
         * sto = co - 1;
         break;
         }
      count++;
      }
   }

if(co == maxlen){
   * sto = co - 1;
   }

if(max < lim || 0 > lim){
   * sta = 0;
   * sto = 0;
   ret = -1;
   }
else{
   ret = (*sto - *sta + 1);
   }

return ret;
}
예제 #8
0
파일: xenbus_probe.c 프로젝트: 020gzh/linux
void xenbus_dev_changed(const char *node, struct xen_bus_type *bus)
{
	int exists, rootlen;
	struct xenbus_device *dev;
	char type[XEN_BUS_ID_SIZE];
	const char *p, *root;

	if (char_count(node, '/') < 2)
		return;

	exists = xenbus_exists(XBT_NIL, node, "");
	if (!exists) {
		xenbus_cleanup_devices(node, &bus->bus);
		return;
	}

	/* backend/<type>/... or device/<type>/... */
	p = strchr(node, '/') + 1;
	snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p);
	type[XEN_BUS_ID_SIZE-1] = '\0';

	rootlen = strsep_len(node, '/', bus->levels);
	if (rootlen < 0)
		return;
	root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node);
	if (!root)
		return;

	dev = xenbus_device_find(root, &bus->bus);
	if (!dev)
		xenbus_probe_node(bus, type, root);
	else
		put_device(&dev->dev);

	kfree(root);
}