Exemple #1
0
void main (void) {
   pdata char buff[MAXLINE];

                      /*Required for Serial Interface*/
   SCON = 0x52;       /*Serial port configuration*/
   TMOD = 0x20;
   TCON = 0x40;
   TH1  = 0xf3;       /*2403 baudrate @12mhz*/

   while(TRUE){
      memset(buff, 0, sizeof(buff));
      prtline("Enter Line: ");
      getline(buff);
      PROMPT;
      puts(buff);

      /*Reverse the characters in the line*/
      /*Reverse the words in the line*/
      rev_word(buff, buff + strlen(buff) - 2); 
      reverse_words(buff); 
      PROMPT;
      puts(buff);

      /*Convert the line to its original form*/
      rev_word(buff, buff + strlen(buff) - 2);
      reverse_words(buff);
   
      /*Sort the characters in the words in alphabetical order*/
      alph_sort_words(buff);
      PROMPT;
      puts(buff);
   }
}
int main(int argc, char **argv) {
//  char line[80];
//  fgets(line, sizeof(line), stdin);
  int failed = 0;
  char line[] = "hello this is easy\n";
  reverse_words(line);
  if (strcmp(line, "easy is this hello\n")) {
    failed = -1;
    printf("error, line %s not equal to 'easy is this hello\n'", line);
  }
  line[0] = '\0';
  reverse_words(line);
  if (strcmp(line, "")) {
    failed = -1;
    printf("error, line %s not equal to ''", line);
  }
  line[0] = '\n';
  line[1] = '\0';
  reverse_words(line);
  if (strcmp(line, "\n")) {
    failed = -1;
    printf("error, line %s not equal to '\n'", line);
  }
  return failed;
}
include <stdio.h>
#include <string.h>
#include <assert.h>
#include "reverse-words.h"
#include <stdlib.h>

int main() {
	char test1[] = "Hello my friends!";
	reverse_words(test1);
	assert(strcmp("friends! my Hello",test1) == 0);
	printf("true1\n");
	char test2[] = "Hello";
	reverse_words(test2);
	assert(strcmp("Hello",test2) == 0);
	printf("true2\n");
	char test3[] = "Potato           420";
	reverse_words(test3);
	assert(strcmp("420           Potato",test3) == 0);
	printf("true3\n");
	char test4[] = "";
	reverse_words(test4);
	assert(strcmp("",test4) == 0);
	printf("true4\n");
	char test5[] = "j";
	reverse_words(test5);
	assert(strcmp("j",test5) == 0);
	printf("true5\n");
	return 0;
}
// Unit test.
bool test_reverse_word(std::ifstream &file)
{
	if(!file.is_open())
	{
		throw; //file not open
	}

	std::string line;

	while(getline(file,line))
	{
		//make a deep copy...
		std::string expected = line + "";

		char* exp = &expected[0];
		char* actual = &line[0];

		reverse_words_quick_and_dirty(exp);
		reverse_words(actual);
		
		if(strcmp(actual,exp) != 0)
		{

			std::cout << "expected: " << exp << std::endl;
			std::cout << "actual  : " << actual << std::endl;
			std::cout << "Test Failed!" << std::endl;
			return false;
		}
	}

	std::cout << "Test Passed!" << std::endl;

	return true;
}
void check_reverse_words(const char * input, const char * expected) {
	char * actual = new char[strlen(input)+1];
 	strcpy(actual, input);
	reverse_words(actual);
	BOOST_CHECK_MESSAGE(strcmp(expected,actual)==0, "expecting '" << expected << "' but got '" << actual << "'");

	free(actual);
}
void str_words_in_rev(char *input, int len) {

    int length;
    length = find_length(input);
    reverse(input, 0, length - 1);
    reverse_words(input, length);


}
Exemple #7
0
int main(int argc, char *argv[]) {
  int len;

  if(argc > 1) {
    reverse_words(argv[1]);
    printf("%s\n", argv[1]);
  }

  return 0;
}
int main(int argc, char **argv)
{
    std::string input;
    if (argc < 2)
        input = "Funny this is";
    else
        input = std::string(argv[1]);

    std::cout << reverse_words(input) << std::endl;
}
Exemple #9
0
/*
 * Question 0:
 *
 * Write a program where the function main prints out all the command line 
 * arguments in order, one per line.
 */
int main(int argc, string argv[]) {
  for (int i = 0; i < argc; i++) {
    printf("arg[%d]: %s\n", i, argv[i]); 
    printf("length: %d\n", string_len(argv[i]));
    printf("num occurrences of %c: %d\n", 'e', num_occur(argv[i],'e'));
    reverse_string(argv[i],0,4);
    printf("reverse, start = %d, end = %d: %s", 0, 4, argv[i]);
    printf("\n");
  }
  
  char s[] = "be sure to drink your ovaltine";
  printf("%s\n", s);
  reverse_words(s);
  printf("%s\n", s);
  return 0;
}
Exemple #10
0
int main(int argc, char *argv[])
{
    FILE *file = fopen(argv[1], "r");
    if ( file != NULL ) {
        char line[200];
        char *pos;

        while( fgets(line, sizeof line, file) != NULL ) {
            if ((pos = strchr(line, '\n')) != NULL)
                *pos = '\0';
            reverse_words(line);
        }
    }

    return 0;
}
int main (void) 
{
    std::vector<std::string> strs = {"",
             "Ciao",
             "Hello world!",
             "Hello, today is a very beatiful day",
             "Hello, today is a very beatiful day.",
             "Hello, today, is, a, very, beatiful, day.",
             "How are you? Very good, thank you!"};

    for (auto& str: strs) {
        reverse_words(str);
        std::cout << str << std::endl;
    }
    return 0;
    
}
Exemple #12
0
	TEST(TEST_UTILS, reverse_words_1)
	{
		string s = "a";
		reverse_words(s);
		EXPECT_EQ(s,"a");
		s = "";
		reverse_words(s);
		EXPECT_EQ(s,"");

		s = "   a";
		reverse_words(s);
		EXPECT_EQ(s,"a");

		s = "   this   is   blue  sky      ";
		reverse_words(s);
		EXPECT_EQ(s,"sky blue is this");

		s = "   this   is   blue  sky";
		reverse_words(s);
		EXPECT_EQ(s,"sky blue is this");

		s = "this   is   blue  sky   ";
		reverse_words(s);
		EXPECT_EQ(s,"sky blue is this");

		s = "this";
		reverse_words(s);
		EXPECT_EQ(s,"this");

		s = "this  ";
		reverse_words(s);
		EXPECT_EQ(s,"this");

		s = "   this  ";
		reverse_words(s);
		EXPECT_EQ(s,"this");
	}
int main(int nargs, char** args) {
	if(nargs != 2) {
		printf("was expecting one argument, the string with words to be reversed\n");
		return -1;
	}
	
	char * original = args[1];
	char * for_rev_str = new char[strlen(original)+1];
	char * for_rev_words = new char[strlen(original)+1];
 	strcpy(for_rev_str, original);
 	strcpy(for_rev_words, original);

	reverse_str(for_rev_str, (for_rev_str+strlen(for_rev_str)-1));
	reverse_words(for_rev_words);

	printf("input string:    '%s'\n", original);
	printf("reversed string: '%s'\n", for_rev_str);
	printf("words reversed:  '%s'\n", for_rev_words);
}
// Main driver for program1
int main(int argc, char** argv)
{
	options opts = parse_cmd_line(argc, argv);

	if(opts.do_help)
	{
		if(opts.error)
		{
			std::cout << "Error parsing command line." << std::endl;
		}

		do_help(argv);
		return -1;
	}

	if(opts.run_tests)
	{
		std::ifstream file;
		file.open(opts.input_file,std::ifstream::out);
		
		test_reverse_word(file);
		file.close();
		return 0;
	}

	char* sentence = &opts.sentence[0];
	std::cout << "Input sentence:  " << opts.sentence << std::endl;

	if(opts.use_quick_and_dirty)
	{
		reverse_words_quick_and_dirty(sentence);
	}
	else
	{
		reverse_words(sentence);
	}

	std::cout << "Output sentence: " << sentence << std::endl;

	return 0;
}
int main(){
	char str[] = "I Love my country";
	reverse_words(str);
	printf("Reversed string: %s\n",str);
	return 0;
}
Exemple #16
0
void main() {
	char str[] = " string not is a coena   af  ";
	printf("str:%s\n",str);
	reverse_words(str);
	printf("str:%s\n",str);
}
Exemple #17
0
int main() {
    /*char c;*/
    int choice;
    int n;
    char str[] = "gee  ks f  or g  ee ks ";
    char path[128];
    char S[128], T[128];
    char *pattern = "-20";
    char str1[32], str2[32];

    char **s;
    /*do {*/

	printf("MENU OPTIONS\n");
	printf("1 -- remove spaces from string\n");
	printf("2-- Check if a given sequence of moves for a robot is circular or not\n");
	printf("3 -- Regex matching problem\n");
	printf("4 -- Palindrome detection with non-alphanumeric characters\n");
	printf("5 -- Normalize the path\n");
	printf("6 -- replace space by percentage20 in a string\n");
	printf("7 -- minimum window substring\n");
	printf("8 -- integer to english words\n");
	printf("9 -- restore IP addresses\n");
	printf("10 -- check if strings are isomorphic\n");
	printf("11 -- function to determine if a string is a valid number without using any built-in function\n");
	printf("12 -- reverse string\n");
	printf("13 -- reverse words in a sentence\n");
	printf("14 -- shortest distance between words\n");
	printf("15 -- shortest distance between words\n");
	
	

	printf("\n");
	printf("Enter your choice\n");
	scanf("%d",&choice);
	switch(choice){
	    case 1:
		removeSpaces(str);
		printf("%s", str);
		break;

	    case 2:
		printf("Enter path\n");
		scanf("%s", path);
		printf("path is circular: %s", checkCircularpath(path)?"yes":"no");
		break;

	    case 4:
		palindrome();
		break;
		
	    case 5:
		printf("Enter path\n");
		fgets(path, 128, stdin);
		printf("Normalized path: %s\n", normalize(path));
		break;

	    case 6:
		memset(path, '\0', 128);
		printf("Enter string\n");
		scanf("%s", path);
		/*gets(path);*/
		replace_spaces(path, pattern);
		printf("%s\n", path);
		break;

	    case 7:

		printf("Enter the string\n");
		scanf("%s", S);
		printf("Enter the pattern\n");
		scanf("%s", T);

		min_window_substring(S, T);
		    break;

	    case 8:
		    /*interger_to_english_words();*/
		    break;

	    case 9:
		    restore_ip_address();
		    break;

	    case 10:
		    printf("Enter strings of equal length\n");
		    printf("Enter string 1\n");
		    scanf("%s", S);
		    printf("Enter string 2\n");
		    scanf("%s", T);
		    printf("Strings are isomorphic : %s\n", isomorphic_strings(S, T)?"Yes":"No");
		    break;

	    case 11:
		    printf("Enter the string\n");
		    scanf(" %[^\n]s", S); //reading a space through scanf
		    /*fgets(stdin, S, sizeof(S));*/
		    printf("Is number : %s\n", is_valid_number(S)?"yes":"no");
		    break;

	    case 12:
		    printf("Enter the string\n");
		    scanf(" %[^\n]s", S);  //make scanf work with spaces  //make scanf work with spaces
		    reverse_string(S, strlen(S));
		    print_string(S, strlen(S));
		    break;
	    case 13:
		    printf("Enter the sentence\n");
		    scanf(" %[^\n]s", S);  //make scanf work with spaces  //make scanf work with spaces
		    /*fgets(S, 128, stdin);*/
		    reverse_words(S);
		    print_string(S, strlen(S));
		    break;

	    case 14:
		    printf("Enter number of words\n");
		    scanf("%d", &n);
		    s = create_2Dchar_array(n, 128);
		    input_2Dchar_array(s, n, 128);

		    printf("enter word 1\n");
		    scanf("%s", str1);
		    printf("enter word 2\n");
		    scanf("%s", str2);
		    printf("Shortest distance between %s and %s : %d\n", str1, str2, shortest_distance(s, n, str1, str2));
		    break;





		    




	    default:
		printf("Invalid option\n");
		break;
	}
	printf("\n\n");
    /*}while((c=getchar())!='q'); */
    return 0;
}
Exemple #18
0
Fichier : sde.c Projet : IPXSam/sde
static inline void feed_ram(FILE *f, struct cpu *cpu)
{
	fread(cpu->ram, 2, RAM_SIZE, f);
	reverse_words(cpu->ram, RAM_SIZE + 1);
}